如何覆盖jenkinsfile的默认参数? [英] How can I override a jenkinsfile's default parameters?

查看:196
本文介绍了如何覆盖jenkinsfile的默认参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时,我们想创建使用同一Jenkinsfile而不是单个Jenkinsfile的多个作业.例如,发生这种情况可能是因为我们要维护根据参数划分的日志,而不是在单个任务上寻找正确的日志.

Sometimes, we want to create multiple jobs that use the same Jenkinsfile instead of a single one. This could happen for example because we want to maintain logs divided based on parameters, instead of having a single job on which look for the right log.

但是,在这种情况下,我们不能使用Jenkinsfile中的参数定义,因为我们在工作实例上定义的任何默认值都将被后续执行时使用Jenkinsfile中定义的内容覆盖(这是如果未定义默认值,也会发生这种情况.

However, in this case, we can't use the parameter definition in the Jenkinsfile, because whatever default value we would define on the job instance would be overwritten by the following execution with whatever is defined in the Jenkinsfile (and this is also happening if we don't define a default value).

因此,在这种情况下,我们找出的唯一方法是删除Jenkinsfile中的参数定义,然后直接在作业上定义参数,这不是最佳选择.

So, in this situation, the only way we figure out is to remove the parameter definition in the Jenkinsfile and define the parameters directly on the jobs, which is kind of not optimal.

我的意思是,我同意,在大多数情况下,这是正确的做法,因为您不希望参数不同步且不版本化,但是有一种方法可以指定Jenkins跳过该参数重新配置还是覆盖Jenkinsfile中编写的默认参数?可以逐个作业激活/停用的内容.

I mean, I agree that this is the right behavior in most of the cases, as you don't want your parameter to be out of synch and not versioned, but is there a way to specify to Jenkins to skip the parameter reconfiguration or to override the default parameter written in the Jenkinsfile? Something that can be activated/deactivated job by job.

推荐答案

我自己遇到了这个问题,我们这样解决了它:

Had this problem myself, we solved it like this:

string(name: 'parameterName', defaultValue: params.parameterName ?:'your default value')

现在,将不会覆盖通过Jenkins作业配置定义的默认值.

Now the default values defined through Jenkins job configuration will not be overridden.

这篇关于如何覆盖jenkinsfile的默认参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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