简体   繁体   English

如何在所有分支上的 Jenkins 中触发 github-webhook

[英]How to trigger github-webhook in Jenkins on all branches

I want that my Jenkins job will be triggered by commits to each one of my branches in my github repo.我希望我的 Jenkins 作业将通过提交到我的 github 存储库中的每个分支来触发。

I have a GitHub repo with this webhook to my Jenkins with this payload URL: http://<my-jenkins-ip>:8080/github-webhook/ I have a GitHub repo with this webhook to my Jenkins with this payload URL: http://<my-jenkins-ip>:8080/github-webhook/

the payload delivery status is 200 OK.有效载荷传递状态为 200 OK。

In my Jenkins server, I have a pipeline job that declared like this:在我的 Jenkins 服务器中,我有一个这样声明的管道作业:

pipeline {
    agent  {
        label 'master'
    }
  
    stages {
        stage('scm') {
            steps {
                 dir("$WORKSPACE/azure-voting-app-redis") {
                     git  'https://github.com/einavle/azure-voting-app-redis'
                 }
            }
        }
}

In the job 'Build trigger section' I'm checking the "GitHub hook trigger for GITScm polling"在“构建触发器部分”作业中,我正在检查“GitHub 钩子触发器用于 GITScm 轮询”

I'm expecting the job to be triggered on each commit to any of the branches in my Github repo.我希望每次提交到我的 Github 存储库中的任何分支时都会触发该作业。 But the actual behavior is that the job is triggered only by commits to the master branch.但实际行为是作业仅由提交到主分支触发。

I'm asking:我在问:

  1. How do I configure the job to be triggered by commits to any of the branches?如何将作业配置为由对任何分支的提交触发?
  2. How can I fetch the branch name of the last commit (that triggered the job)?如何获取最后一次提交(触发作业)的分支名称?

the answer to 1 is: instead of git 'https://github.com/einavle/azure-voting-app-redis' use: git branch: '**', url: 'https://github.com/einavle/azure-voting-app-redis' 1 的答案是:而不是git 'https://github.com/einavle/azure-voting-app-redis'使用: git branch: '**', url: 'https://github.com/einavle/azure-voting-app-redis'

The answer to 2 is to use git rev-parse --abbrev-ref HEAD to take the triggering branch name 2的答案是使用git rev-parse --abbrev-ref HEAD取触发分支名

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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