Webhook should ignore changes in specific directory

14 views
Skip to first unread message

Yogesh B

unread,
Sep 8, 2020, 5:01:21 AM9/8/20
to Jenkins Users
Hi All,

I am using webhook to trigger my declarative pipeline job.
I  want to ignore the directory in my github project, whenever there is changes/commits to particular directory it should not trigger the build. Apart from that directory it should trigger the build.
Is there any way we can achieve this in jenkins pipeline?


Regards,
Yogesh Bidari

Gianluca

unread,
Sep 8, 2020, 5:12:03 AM9/8/20
to Jenkins Users
The only way I found to achieve that it's using "when" expression of "stage" with a function I've built to check if thing changed.

when {
expression {
    FSTChangePatterns.any{pattern -> sideCars.areFilesChanged(pattern)}
}
}

Where the areFilesChanged is:

// There is a bug in the changeset Jenkins command: https://issues.jenkins-ci.org/browse/JENKINS-44849
// ---
// It returns true if the list of changed files in the PR matches the grep pattern passed
// NOTE: it will always returns true in case the build is running on a branch and not on a PR
// because we always want to run a full pipelines on master, release and feature branches
def areFilesChanged(grepPattern) {
if (!env.CHANGE_TARGET) return true
sh(
// NOTE: the triple-dot are necessary to get the same diff result shown by GitHub PRs
script: "git diff origin/${env.CHANGE_TARGET}...HEAD --name-only | grep '${grepPattern}'",
returnStatus: true
) == 0
}

Cheers,
Gianluca.
Reply all
Reply to author
Forward
0 new messages