Active Choices Plugin 插件

官方定义:

The Active Choices plugin allows the creation of dynamic and interactive parameters for freestyle Jenkins jobs. Active Choice parameters can be dynamically updated and can be rendered as combo-boxes, check-boxes, radio-buttons or rich HTML.

安装方法

直接进入插件管理中心搜索 Active Choices 安装即可。

使用

Active Choices Parameter

1、参数化构建中选择 *Active Choices Parameter *
2、Groovy script 编写具体脚本,如下:

图中是读取文件的内容,也可以直接 return [1,2,3] 使用。

3、Choice Type:可以选择类型,可以设置为单选和多选,还有 radio buttons 这种单选框,check box 是复选框,可以根据自己的需求来使用

4、Fallback Script:当上面 Groovy script 执行出错的时候会展示 Fallback Script 中定义的执行结果

Active Choices Reactive Parameter

Active Choices 插件还有一个好用的功能,就是当有多个参数时,第二个参数的值,会根据第一个参数选择的值进行变换。

例如:我们出很多渠道包,渠道码需要根据不同的账号或者规则去展示。那就需要参数是变化的
1、参数化构建中选择 Active Choices Reactive Parameter
2、Groovy script 编写具体脚本,如下:

图中是直接定义的结果,也可以读取文件
3、Referenced parameters:需要参考的参数,如果是根据第一个参数变化的,则填写参数 1 的名称
4、Enable filters:勾选,则支持过滤

Active Choices Reactive Reference Parameter

作展示,根据脚本展示不同的结果。如下图所示;

说明:默认【Active Choices Reactive Reference Parameter 】的值,不传递到构建环境的,如果需要传递到构建环境,需要如下使用:

最终界面展示如下:

#### 参考文档
1、收集了各种脚本:https://github.com/jenkinsci/jenkins-scripts/tree/master/scriptler
2、官方文档:https://wiki.jenkins.io/display/JENKINS/Active+Choices+Plugin


↙↙↙阅读原文可查看相关链接,并与作者交流