jenkinsjenkins-pluginsjenkins-github-plugin

Polling from multiple repositories in Jenkins


I couldn't find an answer for my question on stack, sorry if it is a duplicate.

Let's say I have repo A on Github, where my Jenkinsfile is, and repo B on Github, where all my source code is.

For my job, I've set 'Pipeline script from SCM' from repo 'A', added 'Polling ignores commit in certain paths' with included region containing only this Jenkinsfile.

In Jenkinsfile, I'm using checkout plugin to pull repo 'B' with added PathRestriction extension. Also I've added pollSCM to 'triggers' with value 'H/5 * * * *'.

But whenever I commit something to repo 'A' without any changes to this Jenkinsfile, build is triggered anyway.

My question is: How can I setup my build to trigger only, when Jenkinsfile in repo 'A' or my source code is changed?


Solution

  • There are two ways to trigger a build only when specific file changes.

     1. script hook: On git server side, create a hook that will check if the last commit changed the Jenkinsfile, if true, send a post to jenkins job configured with 'Trigger build remotely'.

     2. Commit: Create a repo only with the Jenkinsfile, so every commit on this repo will be a change on Jenkinsfile.

    I strong advise you to change your approach and use Jenkins shared library, this is a much better way to share and manager pipeline across multiple projects / jobs