|NO.Z.00369|——————————|CloudNative|——|KuberNetes&CI/CD.V07|——|Jenkins.v06|级联变量.v02|
一、Jenkins级联变量
### --- 创建级联变量pod
~~~ 根据上一个变量不同的取值,而进行下一个变量进行取值。
~~~ Dashboard——>Enter an item name:pipeline-var-active——>Pipeline——>ok——>END
### --- 变量一:Active Choices Parameter:创建choices类型变量
~~~ # 变量一:
~~~ General——>This project is parameterized——>Active Choices Parameter——>Name:TEST_ENV——>Script:Groovy Script:return ['test1', 'test2', 'test3']——>
~~~ ——>Fallback Script——>Groovy Script:return ['error']——>Choice Type:Single Select:下拉选项——>Save——>
~~~ ——>Choice Type:Radio Buttons:单选——>Enable filters:过滤——>Save——>
~~~ ——>Choice Type:Multi Select:多选——>Enable filters:过滤——>Save——>
~~~ ——>Choice Type:Check Boxes:多选——>Enable filters:过滤——>Save——>
~~~ # 应用场景:
~~~ 可以把这个Job做成多项目的Job ;同时发布很多模块,需要哪个应用可以勾选起来。




二、级联变量
### --- 变量二:Active Choices Reactive Reference Parameter:级联变量
~~~ General——>This project is parameterized——>Active Choices Parameter
~~~ ——>Name:TEST_ENV——>Script:Groovy Script:return ['test1:selected', 'test2', 'test3']
~~~ ——>Choice Type:Radio Buttons——>
~~~ test1:selected:表示test1会默认勾选上

### --- 变量二:
~~~ General——>This project is parameterized
~~~ ——>Active Choices Reactive Parameter:参考另一个变量的值来取值
~~~ ——>Name:IMAGE_NAME——>Groovy Script:配置参数见下文代码
~~~ ——>Choice Type:Check Boxes
~~~ ——>Referenced parameters:TEST_ENV(级联哪一个变量的参数)——>Save——>
### --- 根据第一个不同的取值来打印第二个变量
if (TEST_ENV.equals('test1') ) {
return ['test1-image1', 'test1-image2']
} else if (TEST_ENV.equals('test2') ) {
return ['test2-image1', 'test2-image2']
} else if (TEST_ENV.equals('test3') ) {
return ['no image']
}


三、pipeline语法
### --- pipeline语法
~~~ Jenkins pipeline语法:https://www.jenkins.io/doc/book/pipeline/syntax/
~~~ 中文文档:https://www.jenkins.io/zh/doc/book/pipeline/syntax/
~~~ Jenkins Active Choice parameter:https://plugins.jenkins.io/uno-choice/
Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart
——W.S.Landor
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通