如何将构建工件传递给 Jenkins 中的另一项工作

How to pass build artifact into another job in Jenkins

设置

我在 Jenkins 有两份工作:

目前,deploy master 有 "Copy artifacts from another project" 个使用 "latest successful build" 的构建步骤。

我的目标

我想将此步骤从 "latest successful build" 更改为 "specified by a build parameter" 以便我可以在部署时 select 特定构建而无需每次修改 deploy master 作业的配置.

我试过的

首先,我改为"specified by a build parameter"。

然后我勾选了"This project is parameterized"旁边的框并为BUILD_SELECTOR添加了一个字符串参数。

然后我 selected 构建并输入输入 47 这是来自 build master 作业的构建号。

此外,我尝试了 api 调用

$.ajax({
  type: 'POST',
  url: 'https://jenkins/job/deploy%20master/build?token=abc7f5abc0c45abcea0646ed858abcde&BUILD_SELECTOR=47'
});

结果

两次都失败了,输出如下:

Started by user styfle
[EnvInject] - Loading node environment variables.
Building in workspace C:\Jenkins\jobs\deploy master\workspace
ERROR: Unable to find a build for artifact copy from: build master
Started calculate disk usage of build
Finished Calculation of disk usage of build in 0 seconds
Started calculate disk usage of workspace
Finished Calculation of disk usage of workspace in 0 seconds
Finished: FAILURE

问题

如何正确配置它以便在部署时指定内部版本号(或其他标识符)?

更新解决方案

感谢 Gerold 的回答,我的解决方案是添加一个 "Build selector for Copy Artifact" 参数,并使用新的环境变量 link 到我已经添加的字符串参数。

Jenkins 中每个 project/job 只有一个工作区。构建目录仅包含有关构建及其结果的信息。

两者的根目录在Manage JenkinsConfigure SystemAdvanced....

要部署以前构建的工件,您必须将其复制到 build master 中的其他位置,并稍后从 deploy master 访问它。

更新:

查看 Which build 的内联帮助 → 参数名称:

A parameter with this name should be added in the build parameters section above. There is a special parameter type for choosing the build selector.

使用这个复制工件的构建选择器而不是字符串参数

在下游项目中添加以下内容。 "Build selector for Copy Artifact" 而不是 "String Parameter"

从另一个项目复制工件

就是这样。单击 "Build with Parameters" 并传递内部版本号