简体   繁体   English

Jenkins 2个分支的自动构建触发器

[英]Jenkins Auto Build Trigger for 2 branches

So I'm currently trying to build a Jenkins pipeline which is automatically triggered by commits to one of two branches via bitbucket webhooks. 因此,我目前正在尝试构建一个Jenkins管道,该管道由通过bitbucket webhooks对两个分支之一的提交自动触发。

In order for the job to start working, I have to manually trigger the job which initiates a build for one of the two branches. 为了使该作业开始工作,我必须手动触发该作业,该作业将启动两个分支之一的构建。 From here I'm able to commit and push to that branch and see the Jenkins job automatically being triggered. 从这里,我可以提交并推送到该分支,并看到Jenkins作业自动被触发。

The issue I'm having is that it never builds the other branch even when committing/pushing changes. 我遇到的问题是,即使提交/推动更改,它也永远不会构建另一个分支。

Can anyone help me find out why only one branch is built and not the other? 谁能帮助我找出为什么只建立一个分支而不建立另一个分支的原因? (it's the develop branch which is triggered) (这是触发的开发分支)

String folderPath = 'folder/path'
folder("$folderPath")

pipelineJob("$folderPath/the-pipeline") {
  description 'WARNING: This pipeline is generated automatically any manual changes may be overwritten.'
  triggers {
    bitbucketPush()
  }
  definition {
    cpsScm {
        scm {
            git {
                remote {
                    url 'git@bitbucket.company/project.git'
                    credentials 'bitbucket-credentials'
                }
                branches('develop', 'master')
            }
        }
        scriptPath("Jenkinsfile")
    }
    concurrentBuild(false)
}
logRotator {
    daysToKeep(-1)
    numToKeep(15)
    artifactDaysToKeep(-1)
    artifactNumToKeep(15)
}

So I'm not sure if this is a bug what I found was the first branch in the 'branches' was the one being triggered and the others were ignored. 因此,我不确定这是否是一个错误,是否发现“分支”中的第一个分支被触发而其他分支被忽略了。 I instead changed 'branches' to 'branch' using a regex instead :^((ref[\\/])?origin[\\/])?(master|develop)$ 我改用正则表达式将'branches'更改为'branch' :^((ref[\\/])?origin[\\/])?(master|develop)$

Have a look here for more info, https://jenkins.io/doc/pipeline/steps/workflow-scm-step/ . 在这里查看更多信息, https://jenkins.io/doc/pipeline/steps/workflow-scm-step/ Search for :<regular expression> 搜索:<regular expression>

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

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