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!






Are you using a Jenkinsfile or the Web-UI?

– Michael
Sep 15 '18 at 5:13






@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.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)