|NO.Z.00369|——————————|CloudNative|——|KuberNetes&CI/CD.V07|-----------------------------------------------------------|Jenkins.v06|級聯變數.v02|
阿新 • • 發佈:2022-04-01
[CloudNative:KuberNetes&CI/CD.V07] [Applications.KuberNetes] [|Jenkins變數使用|Jenkins級聯變數|]
一、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
來自為知筆記(Wiz)