目录
1. Pipeline script:
1.1.代码说明:
2. 实现效果:
3.联动说明:
4.Jenkins安装插件
1. Pipeline script:
properties([
parameters([
[$class: "ChoiceParameter",
choiceType: "PT_SINGLE_SELECT",
description: "Select the Env Name from the Dropdown List",
filterLength: 1,
filterable: false,
name: "Env",
randomName: "choice-parameter-5631314439613978",
script: [
$class: "GroovyScript",
fallbackScript: [
classpath: [],
sandbox: true,
script:
'''return["Could not get Env"]'''
],
script: [
classpath: [],
sandbox: true,
script:
'''return["Dev","QA","Stage","Prod"]'''
]
]
],
[$class: "CascadeChoiceParameter",
choiceType: "PT_SINGLE_SELECT",
description: "Select the Server from the Dropdown List",
filterLength: 1,
filterable: false,
name: "Server",
randomName: "choice-parameter-5631314456178619",
referencedParameters: "Env",
script: [
$class: "GroovyScript",
fallbackScript: [
classpath: [],
sandbox: true,
script:
'''return["Could not get Environment from Env Param"]'''
],
script: [
classpath: [],
sandbox: true,
script:
''' if (Env.equals("Dev")){
return["devaaa001","devaaa002","devbbb001","devbbb002","devccc001","devccc002"]
}
else if(Env.equals("QA")){
return["qaaaa001","qabbb002","qaccc003"]
}
else if(Env.equals("Stage")){
return["staaa001","stbbb002","stccc003"]
}
else if(Env.equals("Prod")){
return["praaa001","prbbb002","prccc003"]
}
'''
]
]
]
])
])
pipeline {
agent any
stages {
stage ("Example") {
steps {
script{
echo 'Hello'
echo "${params.Env}"
echo "${params.Server}"
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"
} }
}
}
}
1.1.代码说明:
这里将参数Server联动到Env:
这里具体联动处理:
2. 实现效果:
3.联动说明:
实现了参数Server随着Env联动
Env参数选择:"Dev"
Server参数只能选择:"devaaa001","devaaa002","devbbb001","devbbb002","devccc001","devccc002"
Env参数选择:"QA"
Server参数只能选择:"qaaaa001","qabbb002","qaccc003"
Env参数选择:"Stage"
Server参数只能选择:"staaa001","stbbb002","stccc003"
Env参数选择:"Prod"
Server参数只能选择:"praaa001","prbbb002","prccc003"
4.Jenkins安装插件
Active Choices Parameter插件和Active Choices Reactive Parameter插件
上面代码中
Env使用Active Choices Parameter插件
Server使用Active Choices Reactive Parameter插件