使用Pipeline项目时,一般都是参数化施工工作。Jenkins的构建需要用到复选框、单选按钮、多选值等参数类型。转到→ManageJenkins→选择ManagePlugins→选择Available选项卡并搜索ActiveSelectionPlugin。安装并重启Jenkins以正确安装插件。我的已经安装了,所以它列在“已安装”选项卡中。ActiveSelectionParameters使用Groovy脚本或Scriptler目录中的脚本为生成参数动态生成值的选择列表。参数可以动态更新,呈现为组合框、复选框、单选按钮或丰富的HTMLUI小部件。按住Ctrl进行多项选择。主动选择响应参数当作业中UI控件的值发生变化时,可以动态更新(主动选择和响应参考参数)这里可以使用IF判断条件,输出相关值。Jenkinsfileproperties([parameters([[$class:'ChoiceParameter',choiceType:'PT_SINGLE_SELECT',description:'SelecttheEnvNamefromtheDropdownList',filterLength:1,filterable:true,name:'Env',randomName:'choice-parameter-5631314439613978',脚本:[$class:'GroovyScript',fallbackScript:[classpath:[],sandbox:false,script:'return[\'CouldnotgetEnv\']'],script:[classpath:[],sandbox:false,script:'return["Dev","QA","Stage","Prod"]']]],[$class:'CascadeChoiceParameter',choiceType:'PT_SINGLE_SELECT',description:'SelecttheServerfromtheDropdownList',filterLength:1,filterable:true,name:'Server',randomName:'choice-parameter-5631314456178619',referencedParameters:'Env',script:[$class:'GroovyScript',fallbackScript:[classpath:[],sandbox:false,script:'return[\'CouldnotgetEnvironmentfromEnvParam\']'],script:[classpath:[],sandbox:false,script:'''if(Env.equals("Dev")){return["devaaa001","devaaa002","开发者bb001","devbbb002","devccc001","devccc002"]}elseif(Env.equals("QA")){return["qaaaa001","qabbb002","qaccc003"]}elseif(Env.equals("Stage")){return["staaa001","stbbb002","stccc003"]}elseif(Env.equals("Prod")){return["praaa001","prbbb002","prccc003"]}''']]]])])管道{环境{vari=""}agentanystages{stage("示例"){步骤{脚本{echo'Hello'echo"${params.Env}"echo"${params.Server}"if(params.Server.equals("CouldnotgetEnvironmentfromEnvParam")){echo"MustbethefirstbuildafterPipelinedeployment.Abortingthebuild"currentBuild.result='ABORTED'return}echo"Crossedparamvalidation"}}}}}【小编推荐】为什么没人跟我说Android手机还能上网?2020年还在用Windows8.1?其实这个操作系统并不老套,微软通过这些新的攻击检测工具增强了Linux的安全性|Google带你体验无限带来的技术有限的可能性
