【问题标题】:Jenkins - Bitbucket PR builder not building correct branchesJenkins - Bitbucket PR 构建器没有建立正确的分支
【发布时间】:2019-08-19 08:36:05
【问题描述】:

我正在设置我的 Jenkinsfile 以允许在为任何分支制作的每个 bitbucket PR 上构建测试(仅在 PR 上)。但是,在进行 PR 时,该插件似乎是针对每个分支构建的。这是插件的错误吗?我正在使用 Bitbucket Pull Request Builder 插件 1.4.30

我的触发器如下

 triggers{

-    bitbucketpr(projectPath:'bitbucket.org/testrepo/django-db.git',

-      cron:'* * * * *',

-      credentialsId:'jenkins_pr_test',

-      repositoryOwner:'testrepo',

-      repositoryName:'django-db',

-      branchesFilter:"*/dev",

-      branchesFilterBySCMIncludes:false,

-      ciKey:'jenkins',

-      ciName:'jenkins',

-      ciSkipPhrases:'',

-      checkDestinationCommit:false,

-      approveIfSuccess:false,

-      cancelOutdatedJobs:true,

-      commentTrigger:'')

-    pollSCM('H/5 * * * *')

-  }

我什至尝试了以下仅针对特定分支构建,但插件仍然构建所有分支。

-      branchesFilter:"*/${BRANCH_NAME}"```

有什么想法吗?

我的阶段如下

     stage('Build and Test Docker image') {

      when { branch "${BRANCH_NAME}" }

       steps {

         script {

            docker.withRegistry("${env.ECR_URL}", "ecr:us-east-1:ecrAccess") {

               customImage = docker.build("${env.IMAGE_NAME}")

               withCredentials([string(credentialsId: 'CODACY_TARGETDB_API', variable: 'CODACY_PROJECT_TOKEN')]) {

                 sh "curl -L \"https://github.com/docker/compose/releases/download/1.23.2/docker-compose-\$(uname -s)-\$(uname -m)\" -o docker-compose"

                 sh "chmod +x docker-compose"

                 sh "./docker-compose -f docker-compose-ci.yml up --exit-code-from web"

               }

               customImage.push()

           }

         }

       }

【问题讨论】:

  • 您是否考虑过使用带有 Bitbucket 分支源插件的多分支管道?只需查看配置,它不仅应该更易于使用,而且还可以满足您的需求,并且可以很好地分别显示分支和 PR。您可以配置如何处理存在 PR 的分支。
  • 嗯,我实际上也在使用它。我想知道它们是否相互冲突。

标签: jenkins jenkins-pipeline bitbucket jenkins-plugins pull-request


【解决方案1】:

在 Triggers 块中编辑 projectPath

*/${sourceBranch}

应该是这样的:

bitbucketpr(projectPath:'*/${sourceBranch}',

【讨论】:

    猜你喜欢
    • 2022-10-06
    • 2018-07-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-23
    • 2015-02-07
    • 2018-07-11
    • 2019-10-20
    相关资源
    最近更新 更多