简体   繁体   中英

How to trigger a Jenkins Pipeline on commit to a branch?

I'm working on triggering a Jenkins Pipeline job when a commit is added to a particular branch on GitHub.

I do not see an appropriate Build Triggers on the Jenkins job options, like I would for a Jenkins Freestyle job.

How do I set a Jenkins Pipeline job to be triggered when a branch is updated with a new commit?

So far, I haven't found explicit answers to this scenario, Only trigger Jenkins Pipeline job on commit to master , only answered regarding Multi-branch jobs.

Any help on this question would be greatly appreciated!

To trigger a Jenkins pipeline with a new commit to Git branch you need to add the web hook on Git repository settings and select Pushes trigger event.

Or if you want Jenkins pipeline to perform some specific step on a specific branch .. you can try adding a condition in your Jenkinsfile like below..

def branchName = "${env.BRANCH_NAME}"
if(branchName == 'dev'){
  ...
}

You need to define a trigger in the repository in case of push for your branch. Additionally, you can poll the scm and define a cron for that.

Do not worry if you have several consecutive pushes in your branch. Jenkins is able to collapse multiple triggers in case of several executions in the queue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM