Jenkins 管道与 Copy Artifact Plugin 从上次完整构建复制工件

Pho*_*nix 2 artifacts jenkins jenkins-pipeline

在声明式 Jenkins 管道中,我们可以使用以下代码从项目的最后一次完整构建中复制工件:

            def lastBuildId = currentBuild?.getPreviousBuild()?.getId()
            copyArtifacts(projectName: "${JOB_NAME}", 
            selector: specific("${lastBuildId}")
            )
Run Code Online (Sandbox Code Playgroud)

但是在插件说明中,我注意到其中一个选择器是“lastCompletedLast”。但我不知道这些选择器的正确用法是什么。如果我使用它是错误的:

                copyArtifacts(projectName: "${JOB_NAME}", 
                selector: lastCompletedLast())
                )
Run Code Online (Sandbox Code Playgroud)

有什么文件吗?

Jas*_*ger 5

使用代码段生成器(在任何流水线作业上使用流水线语法链接)是找到这些类型的好方法。您填写 UI,它会生成 groovy 代码。

根据生成器,以下应该起作用: copyArtifacts projectName: "${JOB_NAME}", selector: lastCompleted()

编辑:我最初添加了最后一个成功的构建选择器,而不是根据 OP 请求。固定为 lastCompleted()