声明式詹金斯管道,检索工件 [英] Declarative jenkins pipeline, retrieve artifact

查看:98
本文介绍了声明式詹金斯管道,检索工件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试触发现有工作并接受生成的 当前作业的工作空间中的工件.

I'm currently trying to trigger an existing job and take in the generated artifacts in the current job's workspace.

以下可以正常工作:

pipeline {
    agent {
        label 'builder-rpm'
    }

    options {
        timestamps()
        ansiColor('xterm')
    }

    stages {
        stage('Build Other pipeline') {
            steps {
                build job: 'Components/components-rpm-build', parameters: [
                    string(name: 'Component', value: 'foo'),
                ]
                copyArtifacts(
                    filter: 'results/*.rpm',
                    fingerprintArtifacts: true,
                    flatten: true,
                    projectName: 'Components/components-rpm-build',
                    selector: lastSuccessful(),
                    target: "${env.WORKSPACE}/dist"
                )
            }
        }
    }
}

问题是lastSuccessful()确实会占用最后一个 成功构建,这意味着如果其他用户设法运行并行 建造速度比我快,我将吸收他们的文物,而不是我的.

The problem of it is that lastSuccessful() will take indeed the last successful build, meaning that if some other user manages to run a parallel build faster than me, I'm going to take in their artifacts instead of mine.

根据此页面 应该有一种使用specific的特定作业的方法:

According to this page there should be a way to use a specific job, with specific:

def built = build('downstream');
copyArtifacts(projectName: 'downstream',
              selector: specific("${downstream.number}"));

但是,没有关于如何在声明式中使用它的解释或示例. 管道.

There's however no explanation nor example on how to use it in a declarative pipeline.

有任何提示吗?

在此先感谢您的帮助.

推荐答案

我找到了一个不错的解决方案:切换到script可以轻松完成这项工作.

I found some decent solution: switching to script simply does the job.

pipeline {
    agent {
        label 'builder-rpm'
    }

    options {
        timestamps()
        ansiColor('xterm')
    }

    stages {
        stage('Build Other pipeline') {
            steps {
                script {
                    def built = build(
                        job:'Components/components-rpm-build',
                        parameters:[
                            string(name:'Component', value:'ew-filesystem'),
                            string(name:'RepoServer', value:'')
                        ]
                    )
                    copyArtifacts(
                        projectName: 'Components/components-rpm-build',
                        selector: specific("${built.number}"),
                        target: "${env.WORKSPACE}/dist",
                        filter: "results/*"
                    )
                }
            }
        }
    }
}

这篇关于声明式詹金斯管道,检索工件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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