简体   繁体   中英

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.

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.

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)$

Have a look here for more info, https://jenkins.io/doc/pipeline/steps/workflow-scm-step/ . Search for :<regular expression>

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