我想有复选框/单选,当用户选中复选框/使用在单选字段,它将创建动态的几个文本框(5).这些文本框2应该包含密码/密钥(所以应该加密/不显示在Jenkins参数.
我尝试使用Jenkins文件和GUI中的Active Choices Parameter和Active Choices Reactive Reference Parameter
举例说明:
我有参数:
Active Choices Parameter
name: use_custom
Groovy Script: return ["true", "false"]
Choice Type: single select
Active Choices Reactive Reference Parameter
name: custom_values
Groovy脚本:
myPassword = ''
if ( use_custom == "true") {
return """
inputBox="<input class='setting-input' name='value' type='password' value=''>"
inputBox="<input class='setting-input' name='value' type='text' value=''>"
"""
echo(text1)
}
else {
return ""
}
选择类型:格式化的html,引用的参数:使用习惯
我创建了2个动态HTML框(仅适用于文本框,而不是用户需要手动输入的密码/密钥(不通过Jenkins Cred)
参数中的示例输出:custom_values:1234,11
- 它以jenkins params格式显示密码(自由文本)
什么是解决方案,允许用户写密码和文本框(2通,3框)时,另一个字段为真(密码不能是自由文本)
groovy pipeline示例(在Env:dev的情况下,create 2 textbox):
properties([
parameters([
[$class: 'ChoiceParameter',
choiceType: 'PT_SINGLE_SELECT',
description: 'Select the Env Name from the Dropdown List',
filterLength: 1,
filterable: true,
name: 'Env',
randomName: 'choice-parameter-5631314439613978',
script: [
$class: 'GroovyScript',
fallbackScript: [
classpath: [],
sandbox: false,
script:
'return[\'Could not get Env\']'
],
script: [
classpath: [],
sandbox: false,
script:
'return["Dev","QA","Stage","Prod"]'
]
]
],
// [$class: 'CascadeChoiceParameter',
// choiceType: 'ET_FORMATTED_HTML',
// description: 'Select the Server from the Dropdown List',
// filterLength: 1,
// filterable: true,
// name: 'Server',
// randomName: 'choice-parameter-5631314456178619',
// referencedParameters: 'Env',
[$class: 'DynamicReferenceParameter',
choiceType: 'ET_FORMATTED_HTML',
omitValueField: true,
description: '123',
name: 'Server',
randomName: 'choice-parameter-5631314456178624',
referencedParameters: 'Env',
script: [
$class: 'GroovyScript',
fallbackScript: [
classpath: [],
sandbox: false,
script:
'return[\'Could not get Environment from Env Param\']'
],
script: [
classpath: [],
sandbox: false,
script:
''' if (Env.equals("Dev")){
inputBox2 = "<input name='value' class='setting-input' type='text'>"
inputBox = "password(name: 'KEY', description: 'Encryption key')"
return[inputBox]
}
else {
return ""
}
'''
]
]
],
[$class: 'DynamicReferenceParameter',
choiceType: 'ET_FORMATTED_HTML',
omitValueField: true,
description: '1234',
name: 'pass',
//randomName: 'choice-parameter-5631314456178624',
referencedParameters: 'Env',
script: [
$class: 'GroovyScript',
fallbackScript: [
classpath: [],
sandbox: false,
script:
'return[\'Could not get Environment from Env Param\']'
],
script: [
classpath: [],
sandbox: false,
script:
''' if (Env.equals("Dev")){
inputBox = "<input name='value' class='setting-input' type='password'>"
return[inputBox]
}
else {
return ""
}
'''
]
]
]
])
])
pipeline {
environment {
vari = ""
}
agent any
stages {
stage ("Example") {
steps {
script{
echo 'Hello'
echo "${params.Env}"
echo "${params.Server}"
echo "${params.pass}"
if (params.Server.equals("Could not get Environment from Env Param")) {
echo "Must be the first build after Pipeline deployment. Aborting the build"
currentBuild.result = 'ABORTED'
return
}
echo "Crossed param validation"
} }
}
}
}
我也试过使用mask_plugin,它从控制台输出屏蔽,而不是从参数屏蔽,有什么想法吗?谢谢
1条答案
按热度按时间piah890a1#
你有没有试