Jenkins 管道将所有参数传递给下游作业 [英] Jenkins pipeline pass all parameters down to downstream jobs

查看:26
本文介绍了Jenkins 管道将所有参数传递给下游作业的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为 buildall 的管道作业,如下所示:

I have a pipeline job named buildall which looks like this:

pipeline {
    stages {
        stage("job1") {
            build job: "job1"
        }
    }
}

buildall 作业有 25 个参数.我想将 buildall 的所有参数传递给 job1.有没有一种简单的方法可以做到这一点,而不是手动指定每个参数?

The buildall job has 25 parameters. I would like to pass all of buildall's parameters down to job1. Is there an easy way I can do that, instead of manually specifying each parameter?

在这个问题中:管道传递参数到下游作业有人问了一个子问题,但从未回答:或者更好的是,有没有一种不那么繁琐的方法,我可以将所有管道参数传递给下游作业.

In this question: Pipeline pass parameters to downstream jobs a sub-question was asked but never answered: Or even better, is there a less cumbersome way in which I can just pass ALL the pipeline parameters to the downstream job.

这和我的问题一样.

推荐答案

以下似乎可行(虽然我还没有广泛测试过):

The following seems to work (I haven't tested it extensively though):

pipeline {
    agent any
    parameters {
        string(name: 'PARAM1', description: 'Param 1?')
        string(name: 'PARAM2', description: 'Param 2?')
    }
    stages {
        stage('Example') {
            steps {
                echo "${params}"
                script {
                    def myparams = currentBuild.rawBuild.getAction(ParametersAction).getParameters()
                    build job: 'downstream-pipeline-with-params', parameters: myparams
                }    
            }
        }
    }
}

缺点:要访问 rawBuild 和 getAction,您必须禁用 Groove 沙箱或在 Jenkins 中在 Manage Jenkins > In-process Script Approval 下批准这些签名.此对话框将显示您可能引入了安全漏洞.因此,您是否愿意承担此风险取决于您的环境.

Drawback: to access rawBuild and getAction you have to disable the Groove sandbox or approve these signatures in Jenkins under Manage Jenkins > In-process Script Approval. This dialog will show you that you might introduced a security vulnerability. So it depends on your environment if you want to take this risk or not.

这篇关于Jenkins 管道将所有参数传递给下游作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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