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

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

问题描述

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

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

例如,我的一项工作被设置为使用某些特定值(均为NON-EMPTY)运行管道,如果触发该任务,管道似乎会将字段b和c的属性重置为''. /p>

如何使管道不触碰詹金斯的工作定义?

例如管道中的参数:

    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

解决方案

嗯,是的,这也是我第一次来.

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

因此,请确保在Jenkinsfile中完全按照所需的方式定义参数,然后运行一次作业,并且GUI将具有相同的参数配置,以便再次运行时,它将要求输入参数.并使用您在DSL中指定的默认值.没什么了.

是的,每次在DSL中修改参数时都必须运行两次,这很烦人. 但是如果您认为必须执行要评估的DSL作业就很有意义,但是首先需要通过UI定义参数来询问参数,然后再检查并评估DSL ...

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

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.

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.

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

e.g. the params in the pipeline:

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

I am not find any help in the documentation at https://jenkins.io/doc/book/pipeline/syntax/#parameters-example

解决方案

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

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.

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.

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