Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build trigger in Jenkins when a specific folder changes

Tags:

git

jenkins

Configure Jenkins: Where it should trigger only when a particular folder changes.

For example: In a file directory: Sample/Folder/ there are 3 sub folders: F1, F2, F3. The jenkins build should be triggered when F3 is changed and should not include F1, F2 in the build. These 3 folders should be independent in regards to the build but should be in the same file directory. Also is there a way we can monitor the changes in the folders?

like image 924
Srikanth Penmetsa Avatar asked Jan 27 '26 02:01

Srikanth Penmetsa


1 Answers

WIth Jenkins pipelines, start your job by querying the build changeset, as in here.

See if an when { anyOf { changeset directive is enough to build if and only when the changeset includes a specific element.

See the pipeline syntax built-in condition

changeset

Execute the stage if the build’s SCM changeset contains one or more files matching the given string or glob. Example: when { changeset "**/*.js" }


As noted by PFudd in the comments:

WARNING: When you create a new branch, the changeset will be empty on the first build. It's also empty if you click "Rebuild". See "Jenkins Pipeline how to check for an empty changelog"

The Jenkins team is aware of this, and due to the complexity of Git, they don't intend to fix it, because there is no universally-correct way to determine the right parent to compare with: see issue JENKINS-26354.

Reference: stackoverflow.com/questions/70307972/…

like image 126
VonC Avatar answered Jan 28 '26 17:01

VonC