Out current Jenkins Pipeline job is setup to build a branch checked out from Git. To do the checkout we use the SCM plugin:
triggers { pollSCM scmpoll_spec: '' } checkout( poll: true, scm: [$class: 'GitSCM', branches: [[name: 'refs/heads/develop']], userRemoteConfigs: [ [url: 'https://git-server/repo.git', name: 'origin', refspec: '+refs/heads/develop:refs/remotes/origin/develop', credentialsId: 'XXX'] ], extensions: [ [$class: 'WipeWorkspace'], [$class: 'CloneOption', honorRefspec: true, noTags: true, reference: '', shallow: false], [$class: 'LocalBranch', localBranch: 'develop'] ], browser: [$class: 'GitList', repoUrl: 'https://git-server/gitlist/repo.git'] ] ) During the build there is a call to npm version patch which updates the package.json file, commits and creates a tag locally. We then push this back to the server side git repository. In order to stop Jenkins from starting another build, we push with options and the post-receive hook ignores these pushes:
git push origin develop --follow-tags --push-option=nobuild The post-receive hook on the server only POSTs to Jenkins when a user pushes as they wont use the options:
"https://jenkins-server/git/notifyCommit?url=https://git-server/repo.git" This is all working wonderfully, however, problem is that when a developer commits to feature branch, a build for the develop branch is started. I'm guessing the following is the cause of the problem:
- commit/push to
developbranch - tag created during building
developbranch - commit/push on
featurebranch - Jenkins sees new tag on develop
branchand starts a build
So I'm looking for a way to either force Jenkins to only consider commits/pushes to a specific branch to trigger a specific build. Or to force Jenkins to ignore changes as part of a tag when considering starting a build.
Note, I found another SO post: Jenkins git commit for specific branch triggers build jobs for other branches too