jenkins - Jenkins 作业参数的动态或条件显示
问题描述
我正在尝试使用以下 jenkins 作业为作业生成 Active Choices 用户可选参数。
我的要求是在选择/取消选择 heartbeat_consumer 复选框时显示/隐藏文本框。我还想将用户输入的值存储在 中heartbeat_consumer_parms
,可以通过env.heartbeat_consumer_parms
. 我计划在下游工作中使用这个值。
pipeline {
agent any
stages {
stage('Parameters'){
steps {
script {
properties([
parameters([
text(
defaultValue: '''''',
name: 'application_servers',
description: 'Please provide semicolon delimited (;) application server list ',
),
[$class: 'CascadeChoiceParameter',
choiceType: 'PT_CHECKBOX',
description: 'Select Services',
name: 'application_services_list',
referencedParameters: 'application_servers',
script:
[$class: 'GroovyScript',
fallbackScript: [
classpath: [],
sandbox: false,
script: "return['']"
],
script: [
classpath: [],
sandbox: false,
script: '''
if (application_servers.length() > 0){
return["heartbeat_consumer", "surgeon_cloud_login", "system_configuration"]
}
'''
]
]
]
])
])
if (application_services_list.contains('heartbeat_consumer')){
text(
defaultValue: '''''',
name: 'heartbeat_consumer_parms',
description: 'Please provide heartbeatconsumer job parms ',
)
}
}
}
}
}
}
在当前的实施中,我根本没有看到该文本框heartbeat_consumer_parms
正在显示。
解决方案
适用于您的场景的管道脚本:
properties([
parameters([
[$class: 'ChoiceParameter',
choiceType: 'PT_CHECKBOX',
description: 'Select the Application Service from the Dropdown List',
filterLength: 1,
filterable: false,
name: 'application_services_list',
script: [
$class: 'GroovyScript',
fallbackScript: [
classpath: [],
sandbox: false,
script:
"return['Could not get the services list']"
],
script: [
classpath: [],
sandbox: false,
script:
"return['heartbeat_consumer', 'surgeon_cloud_login', 'system_configuration']"
]
]
],
[$class: 'DynamicReferenceParameter',
choiceType: 'ET_FORMATTED_HTML',
description: 'SAdd params',
name: 'heartbeat_consumer_parms',
omitValueField: 'true',
referencedParameters: 'application_services_list',
script:
[$class: 'GroovyScript',
script: 'return["Could not get Information"]',
script: [
script: '''
if (application_services_list.equals("heartbeat_consumer")){
inputBox="<input type ='text' id = 'myText' name='value' >"
return inputBox
}
'''
]
]
]
])
])
pipeline {
environment {
vari = ""
}
agent any
stages {
stage ("Example") {
steps {
script{
echo "${params.application_services_list}"
echo '\n'
echo "${params.heartbeat_consumer_parms}"
}
}
}
}
}
请找到输出的屏幕截图:
构建后管道的输出:
推荐阅读
- kotlin - 如果 Kotlin 中的参数不为空,则过滤列表
- firebase - iOS 应用程序在尝试检索推送消息数据属性时关闭且没有错误
- c# - 通过单击列进行排序返回 C# 中的所有列
- python - 在 jupyter 笔记本中使用 pyspark 时如何指定驱动程序类路径?
- windows - IIS 8.5 & 7.5 - 应用程序池回收
- ms-access - 在 Access 表中设置是/否数据类型的默认值
- python - 如何在 UpdateView 中包含删除功能而不是 DeleteView
- arrays - 仅使用一个 if 语句的 Sumproduct 数组
- mongodb - 从 MongoDB Compass 执行命令
- javascript - 如何在 multiscroll.js div 下创建部分?