如何触发另一个需要$ BRANCH变量的Jenkins管道? [英] How to trigger another Jenkins pipeline that needs a $BRANCH variable?

查看:66
本文介绍了如何触发另一个需要$ BRANCH变量的Jenkins管道?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有3条管道.说:

build-and-release build release

我正在重构管道,以便可以从build-and-release内部调用buildrelease作业.遵循以下原则:

I'm refactoring my pipelines, so that I can just call the build and release jobs, from within the build-and-release. Something along these lines:

// build-and-release JenkinsFile
node('master') {
  build job: "build", propagate: true, wait: true
  build job: "release", propagate: true, wait: true
}

// build JenkinsFile
node('master') {
  stage('Build') {
    // do stuff
  }
}

// release JenkinsFile
node('master') {
  stage('Release') {
    // do other stuff
  }
}

这似乎按原样工作,但是buildrelease管道始终假定分支为MASTER.运行build-and-release作业时,选择要构建的分支.

This seems to work as it is, but the build and release pipelines always assume the branch is MASTER. When I run the build-and-release job, I pick what branch I want to build.

如何使其他作业使用从build-and-release中选择的相同$ BRANCH?

How do I make the other jobs use the same $BRANCH that I pick from build-and-release?

推荐答案

您可以将buildrelease作业配置为参数化作业,然后可以将分支名称作为参数发送,如下所示:-

You can configure build and release jobs as parameterized job and then you can send the Branch name as a prameter, as shown below:-

// build-and-release JenkinsFile
node('master') {
  build job: 'build', parameters: [string(name: 'Branch', value: "${env.BRANCH_NAME}")], propagate: true, wait: true
  build job: 'release', parameters: [string(name: 'Branch', value: "${env.BRANCH_NAME}")], propagate: true, wait: true
}

然后您可以在构建和发布的Jenkinsfile中使用 Branch 变量.

And then you can use the Branch variable in Jenkinsfile of build and release.

注意:-您可以在上面的示例中配置任何其他参数类型字符串参数已配置,有关更多信息,请参考

Note:- You can configure any other parameter type in above example String Parameter has been configured, for more information please refer the link

这篇关于如何触发另一个需要$ BRANCH变量的Jenkins管道?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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