jenkins管道PR构建包含错误的分支名称 [英] jenkins pipeline PR build contains wrong branch name

查看:144
本文介绍了jenkins管道PR构建包含错误的分支名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将Jenkins多分支管道与bitbucket一起使用,并且看到一个问题,因为我依赖env.BRANCH_NAME,因此为PR创建的自动构建失败. 问题在于此环境现在没有按预期保存功能分支名称,而是保存PR(例如PR-2,而不是功能/测试分支).

I am using Jenkins multi branch pipeline with bitbucket and I see an issue where the automatic build created for a PR fails as I rely on env.BRANCH_NAME. Problem is that this env now holds not the feature branch name as expected, instead it holds the PR is (e.g. PR-2 instead of feature/test-branch).

我的工作中有代码会根据BRANCH_NAME推送到分支.显然,由于没有名为PR-2的分支,此代码现在失败了.

I have code in my job that pushes to branch based on the BRANCH_NAME. This code obviously now fails as there is no branch named PR-2.

有人见过这个吗,有解决方法吗?

Anyone saw this before and has a workaround?

推荐答案

在我的管道中,有一个阶段会相应地设置构建名称,以防万一我必须使用CHANGE_BRANCH而不是普通的分支名称.

I have a stage in my pipeline setting the build name accordingly in case I have to use the CHANGE_BRANCH instead of the normal branch name.

stage('Set Build Name') {
  steps {
    script {
      if (env.BRANCH_NAME.startsWith('PR')) {
        currentBuild.displayName = "#${env.BUILD_NUMBER} - ${env.CHANGE_BRANCH}"
      } else {
        currentBuild.displayName = "#${env.BUILD_NUMBER} - ${env.BRANCH_NAME}"
      }
    }
  }
}

这篇关于jenkins管道PR构建包含错误的分支名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆