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

查看:475
本文介绍了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,必须在管理Jenkins">进程内脚本批准"下禁用Groove沙箱或在Jenkins中批准这些签名.该对话框将向您显示您可能引入了安全漏洞.因此,是否要冒险承担风险取决于您的环境.

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天全站免登陆