Jenkins Git-Push with master branch only
Jenkins Git-Push with master branch only
This might be a very basic question in terms of jenkins and github integration. However, I am thinking good to ask.
What I am basically looking to do is if anything pushed to master branch of git only then my jenkins job must get triggered. Considering there are multiple feature branches and multiple commits happening on different branches but I am interested only in master branch push.
I did not find good documentation over, could anybody give me any pointer on this.
Help is appreciated, thanks!
@Michael, Does it behave differently for jenkinsfile and web-ui. I am using Jenkinsfile.
– Santosh Dhanasure
Sep 15 '18 at 8:15
probably not, but in case of a Jenkinsfile I can answer in code and not screenshots.
– Michael
Sep 15 '18 at 8:19
1 Answer
1
OK, so you got two options:
Just click on create new item, select pipeline and under "Pipeline" configure as "Pipeline script from SCM" and put your GitHub and in "branches to build" put "*/master".
Alternatively you could add when
conditions to your stages if you use declarative syntax:
when
pipeline
agent any
stages
stage("Build")
when branch 'master'
steps
// do your build
Or if you're using scripted:
node
stage('Build')
if (env.BRANCH_NAME == 'master')
// do your build
See "flow control".
How will this job gets triggered when something pushed to master ? don't we need to configure github to push to jenkins ?
– Santosh Dhanasure
Sep 15 '18 at 13:30
I have not much experience regarding GitHub and Jenkins, but with Bitbucket, you just set the push trigger and due to the "branches to build" setting Jenkins is only triggered for that branch.
– Michael
Sep 15 '18 at 13:42
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Are you using a Jenkinsfile or the Web-UI?
– Michael
Sep 15 '18 at 5:13