简体   繁体   English

将参数从 KEY=VALUE 属性文件传递到下游 Jenkins 作业

[英]Pass parameters from KEY=VALUE properties file to downstream Jenkins job

In my declarative pipeline, I do have the below line to call the downstream job.在我的声明性管道中,我确实有以下行来调用下游作业。

build job: 'my_downstream_job'

I have a file in KEY=VALUE format, how to pass in the parameters from this properties file?我有一个KEY=VALUE格式的文件,如何从这个属性文件中传入参数? Downstream job receive this parameter as KEY .下游作业将此参数作为KEY接收。 Using Jenkins GUI, I use "Parameters from properties file" and put this filename in there and it works, like to know how to do the same with pipeline.使用 Jenkins GUI,我使用“来自属性文件的参数”并将这个文件名放在那里,它可以工作,就像知道如何对管道做同样的事情。

You might need some extra logic to process this file and construct the appropriate list.您可能需要一些额外的逻辑来处理此文件并构建适当的列表。 See https://jenkins.io/doc/pipeline/steps/pipeline-build-step/ for documentation but typically it will look like:有关文档,请参阅https://jenkins.io/doc/pipeline/steps/pipeline-build-step/ ,但通常看起来像:

build(job: "my_downstream_job",
    parameters: [
        new StringParameterValue('MY_NAME', myname_var),
    ],
    propagate: true
)

So you might need to parse your file and create a list if new StringParameterValue's for each line.因此,如果每行都有新的 StringParameterValue,您可能需要解析您的文件并创建一个列表。

It doesn't appear that there is a one-liner way to do this, but I got this to work:似乎没有一种单线方式可以做到这一点,但我做到了:

params = readProperties  file: "params.properties"
build job: 'some_jenkins_job', parameters: [
    string(name: 'PROP_STR', value: params.PROP_STR),
    booleanParam(name: 'PROP_BOOL', value: params.PROP_BOOL),
]

And maybe this is for the best, so it's clear exactly which params are being passed in, just by reading the Jenkinsfile.也许这是最好的,所以只需阅读 Jenkinsfile,就可以清楚地知道传入了哪些参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM