如何确保在运行 Jenkins 管道之前更新参数列表? [英] How to make sure list of parameters are updated before running a Jenkins pipeline?

查看:13
本文介绍了如何确保在运行 Jenkins 管道之前更新参数列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Jenkins 管道项目配置为从 Git 存储库获取其 Jenkinsfile:

A Jenkins pipeline project is configured to fetch its Jenkinsfile from a Git repo:

如果我更改参数列表,例如,从:

If I change the list of parameters, for example, from:

properties([
        parameters([
                string(name: 'FOO', description: 'Choose foo')
        ])
])

到:

properties([
        parameters([
                string(name: 'FOO', description: 'Choose foo'),
                string(name: 'BAR', description: 'Choose bar')
        ])
])

并运行构建,第一次运行不显示新添加的BAR参数:

And run the build, the first run does not show the newly added BAR parameter:

由于更新后的 Jenkins 文件需要存在 BAR 参数,这会导致更改后的第一次构建失败,因为没有向用户提供输入该值的输入.

As the updated Jenkins file expects the BAR parameter to be present, this causes the first build after the change to fail as the user is not presented with an input to enter this value.

有没有办法防止这种情况发生?在显示参数输入页面之前确保 Jenkinsfile 是最新的?

Is there a way to prevent this? To make sure the Jenkinsfile is up-to-date before showing the parameter entry page?

推荐答案

简短的回答:不.如果有一些工具可以解析和处理与构建分开的 Jenkinsfile,那就太好了,但没有.

Short answer: No. It would be nice if there was some facility for parsing and processing the Jenkinsfile separate from the build, but there's not.

Jenkins 在检索、解析和运行 Jenkinsfile 之前不知道新参数,唯一的方法是......运行构建.

Jenkins does not know about the new parameters until it retrieves, parses, and runs the Jenkinsfile, and the only way to do that is to...run a build.

实际上,构建历史将始终落后于"Jenkinsfile;当您更改 Jenkinsfile 中的某些内容时,下一个构建将使用旧"Jenkinsfile 运行,但之后会为构建选择并处理新的 Jenkinsfile.

In effect, the build history will always be "one run behind" the Jenkinsfile; when you change something in the Jenkinsfile, the next build will run with the "old" Jenkinsfile, but pick up and process the new Jenkinsfile for the build after that.

这篇关于如何确保在运行 Jenkins 管道之前更新参数列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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