参数化构建 - Jenkins 管道

Paramertized Build - Jenkins Pipeline

希望有人能指出我正确的方向。

我刚刚开始研究 Jenkins 管道,正在尝试研究如何使用 Jenkinsfile

为已经存在的作业触发参数化构建

在我的 Jenkinsfile 我有

node {
 stage 'Build My Job'
 build job: 'my-build'
}

我需要能够将 Jenkinsfile 配置中的分支名称传递给 运行 的作业吗?如果我有任何误解,请告诉我

谢谢

与其从 Jenkinsfile 开始,不如从可以直接编辑管道脚本的管道作业开始。通过单击 'Pipeline Syntax' link,您可以打开代码段生成器,您可以在其中为特定步骤生成 Groovy:

This Snippet Generator will help you learn the Groovy code which can be used to define various steps. Pick a step you are interested in from the list, configure it, click Generate Groovy, and you will see a Groovy statement that would call the step with that configuration. You may copy and paste the whole statement into your script, or pick up just the options you care about. (Most parameters are optional and can be omitted in your script, leaving them at default values.)

在配置页面select 'This project is parameterized'选择参数类型并输入参数名称

您可以使用 'env.parameterName'

在您的 jenkinsfile 中访问这个新参数值