管道参数和 jenkins GUI 参数如何协同工作? [英] How do pipeline parameters and jenkins GUI parameters work together?

查看:18
本文介绍了管道参数和 jenkins GUI 参数如何协同工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 jenkinsfile 中使用管道,但我不确定如何正确链接 Jenkins 中的作业和管道.

I am using a pipeline in a jenkinsfile and I am not sure how to properly link the job in Jenkins and the pipeline.

我在我的 jenkinsfile 中定义了参数(一些具有默认值,一些没有)并使用来自 jenkins gui 的参数初始化它们.问题是它接缝我的管道中的参数覆盖了我的作业参数,即使管道中没有指定默认值,这意味着管道正在覆盖我在 jenkins 中的作业设置.

I defined parameters in my jenkinsfile (some with default values, some without) and have them initialized from the parameters coming from jenkins gui. The problem is that it seams the parameters in my pipeline are overiding my job parameters, EVEN when no default value is specified in the pipeline which means the pipeline is overriding my job setup in jenkins.

例如,我的一项工作是设置使用某些特定值(全部为非空)运行管道,如果我触发该作业,管道似乎会将字段 b 和 c 的属性重置为 ''.

for example, one of my job is setup to run the pipeline with some specific values (all NON-EMPTY), if I trigger the job, the pipeline seem to reset the properties to '' for fields b and c.

如何让管道不触及我的 jenkins 工作定义?

How to I get the pipeline to not touch my jenkins job definition?

例如管道中的参数:

    properties([
      parameters([
        string(name: 'a',   defaultValue: 'Default A value', description: '', ),
        string(name: 'b',   description: '', ),
        string(name: 'c',   description: '', ),
       ])
])

我在 https://jenkins 的文档中找不到任何帮助.io/doc/book/pipeline/syntax/#parameters-example

推荐答案

啊,是的,这也是我第一次遇到的问题.

Ah, yes, it got me the first time around also.

第一次运行管道时,jenkinsFile DSL 作业定义几乎会覆盖您通过 GUI 输入的整个作业定义.这尤其会影响参数.

The first time that you run the pipeline, the jenkinsFile DSL job definition pretty much overrides the whole job definition that you have entered thru the GUI. That affects the parameters in particular.

所以请确保您在 Jenkinsfile 中准确地定义了参数,然后运行一次作业,GUI 将具有相同的参数配置,因此当您再次运行时,它会询问参数并使用您在 DSL 中指定的默认值.没有别的了.

So make sure you define the parameters exactly how you want them in the Jenkinsfile, then run the job once, and the GUI will have the same config for the parameters, so that when you run again, it will ask for the parameters and use the default values, that you specified in the DSL. There is nothing more to it.

是的,每次修改 DSL 中的参数都必须运行两次,这很烦人.但是,如果您认为必须执行作业才能评估 DSL,这有点道理,但是如果您通过 UI 定义了一些参数,它首先需要询问参数,然后再检查并评估 DSL...

Yes, having to run twice everytime you modify the parameters in the DSL is annoying. But it sort of makes sense if you consider that the job has to execute for the DSL to be evaluated, but first it needs to ask for parameters if you have some defined via the UI, BEFORE it checks out and evaluates the DSL...

这篇关于管道参数和 jenkins GUI 参数如何协同工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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