在Jenkins作业的构建中,是否可以在中途更改构建参数? [英] On a build of a Jenkins job, is it possible to change build parameters midway through?

查看:138
本文介绍了在Jenkins作业的构建中,是否可以在中途更改构建参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用Jenkins使我们的一些构建和测试过程自动化.对于我们的某些过程,开始构建的工程师需要指定一个参数.但是该参数的可能值和最佳值的范围在一天中的整个过程中都会发生变化.

We are using Jenkins to automate several of our build and test processes. For some of our process, the engineer starting the build needs to specify a parameter. But the range of possible and optimal values for that parameter change throughout the course of the day.

我想做的是让工程师指定一个值-如果他们知道最佳值-或将其留为空白并通过早期构建步骤计算出一个值.如果已计算出该值,我希望计算构建步骤可以更新作业的参数值.这样,所有后续构建步骤都不必担心使用参数或对其进行计算,而只需使用参数即可.

What I would like to do is let the engineer specify a value - if they know an optimal value - or leave it blank and have a value be calculated by an early build step. If the value is calculated, I would like the calculating build step to update the parameter value of the job. That way, all subsequent build steps don't have to worry about using the parameter or calculating it, they just use the parameter regardless.

它看起来像 Groovy脚本插件也许可以做到,但是我看不到如何设置构建参数,只是获取它们.

It looks like the Groovy Script Plugin might be able to do this, but I can't see how I can SET the build parameters, just GET them.

推荐答案

找到答案:使用 EnvInject插件.功能之一是构建步骤,允许您从设置文件将参数注入"到构建作业中.我使用了一个构建步骤来创建设置文件,然后使用了另一个构建步骤来注入新值.然后,所有后续的构建步骤和构建后的操作均使用新值.

Found the answer: use the EnvInject Plugin. One of the features is a build step that allows you to "inject" parameters into the build job from a settings file. I used one build step to create the settings file, then another build step to inject the new values. Then, all subsequent build steps and post-build operations used the new value.

更新,例如:

要基于现有参数(JOB_NAME)添加新参数(REPORT_FILE),请在 Groovy脚本 框中插入具有新参数或已修改参数的地图:

To add a new parameter (REPORT_FILE), based on existing one (JOB_NAME), inject a map with new or modified parameters in the Groovy Script box:

// Setting a map for new build parameters
def paramsMap = [:]

// Set REPORT_FILE based on JOB_NAME
def filename = JOB_NAME.replace(' ','_') + ".html"
paramsMap.put("REPORT_FILE", filename)

// Add or modify other parameters...

return paramsMap

这篇关于在Jenkins作业的构建中,是否可以在中途更改构建参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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