一. 聲明式流水線(Declarative Pipeline)
所有有效的聲明式流水線必須包含在一個pipeline塊中:
pipeline {
/* insert Declarative Pipeline here */
}
在聲明式流水線中有效的基本語句和表達式遵循與 Groovy 語法相同的規(guī)則,但有以下例外:
Pipeline 的頂層必須是一個塊麻车,具體來說是:pipeline { }动猬。
沒有分號作為語句分隔符。 每個語句都必須在它自己的行上饺鹃。
塊只能由章節(jié)(Sections)、指令(Directives)链瓦、步驟(Steps)或賦值語(assignment statements)句組成慈俯。
屬性引用語句被視為無參數(shù)方法調(diào)用拥峦。 例如略号,input被視為input()璃哟。
Jenkins還提供了聲明式指令片段生成器來幫助生成聲明式流水線指令随闪。
Jenkinsfile一般結構如下:
pipeline {
agent {
//define agent
}
stages {
stage('name') {
steps {
//some scripts
}
}
...
}
}
1. agent (require)
agent聲明整個pipeline腳本或某個stage腳本在jenkins中的運行環(huán)境铐伴,寫在pipeline最外層則是聲明整個pipeline的運行環(huán)境当宴,寫在stage里則是stage的運行環(huán)境户矢。pipeline的最外層必須聲明agent梯浪, 而在stage里則是可選項挂洛。
agent的類型參數(shù):
1.1 any
在任意可用代理上運行pipeline虏劲。
示例:
pipeline {
agent any
stages {
stage {
//optional
agent any
steps {
//do something
}
}
}
}
1.2 none
當在全局聲明agent為none時,那么每一個stage都需聲明自己的agent谷丸。
1.3 label
按在jenkins環(huán)境中設定的label標簽名聲明agent淤井,如label所代表的節(jié)點币狠。
agent {
label 'my-node1'
}
除此之外label還可以與邏輯符號一同使用:
agent {
label 'my-node1' && 'my-node2'
}
agent {
label 'my-node1' || 'my-node2'
}
1.4 node
node聲明運行節(jié)點漩绵,與label功能類似止吐,但是node可以附加選項參數(shù)碍扔, 如customWorkspace:
agent {
node {
label 'my-node1'
}
}
等同于
agent {
label 'my-node1'
}
node附加選項參數(shù):
agent {
node {
label 'my-defined-label'
customWorkspace '/some/other/path'
}
}
1.5 docker
用于基于docker的pipeline流水線不同,在預配置的節(jié)點上或指定label的節(jié)點上創(chuàng)建docker容器二拐。除此之外還可以接收docker run的參數(shù)百新,以及docker registry等參數(shù)饭望。
示例:
agent {
docker 'maven:3.8.1-adoptopenjdk-11'
}
agent {
docker {
image 'maven:3.8.1-adoptopenjdk-11'
label 'my-defined-label'
args '-v /tmp:/tmp'
registryUrl 'https://myregistry.com/'
registryCredentialsId 'myPredefinedCredentialsInJenkins'
}
}
1.6 dockerfile
從一個Dockerfile創(chuàng)建docker容器來運行pipeline流水線杰妓。默認會從構建的根目錄尋找Dockerfile:
agent {
dockerfile true
}
如果項目的Dockerfile存放在子目錄下需通過dir參數(shù)聲明,如果Dockerfile名字是其他自定義名則需通過filename參數(shù)聲明验靡,除此之外還可以通過additionalBuildArgs來設置docker build參數(shù)胜嗓,使用registryUrl來設置docker倉庫辞州,使用registryCredentialsId從jenkins獲取docker倉庫的賬號密碼变过。
示例:
agent {
// Equivalent to "docker build -f Dockerfile.build --build-arg version=1.0.2 ./build/
dockerfile {
filename 'Dockerfile.build'
dir 'build'
label 'my-defined-label'
additionalBuildArgs '--build-arg version=1.0.2'
args '-v /tmp:/tmp'
registryUrl 'https://myregistry.com/'
registryCredentialsId 'myPredefinedCredentialsInJenkins'
}
}
1.7 kubernetes
在kubernetes集群中的一個pod內(nèi)執(zhí)行pipeline流水線岛杀,pod模版將定義在kubernetes{}模塊中类嗤。如果需要在pod中安裝kaniko則可在yaml參數(shù)中聲明遗锣。
示例:
agent {
kubernetes {
label podlabel
yaml """
kind: Pod
metadata:
name: jenkins-agent
spec:
containers:
- name: kaniko
image: gcr.io/kaniko-project/executor:debug
imagePullPolicy: Always
command:
- /busybox/cat
tty: true
volumeMounts:
- name: aws-secret
mountPath: /root/.aws/
- name: docker-registry-config
mountPath: /kaniko/.docker
restartPolicy: Never
volumes:
- name: aws-secret
secret:
secretName: aws-secret
- name: docker-registry-config
configMap:
name: docker-registry-config
"""
}
你需要創(chuàng)建一個aws-secret密鑰提供給kaniko來進行ECR身份驗證精偿,此密鑰需包含~/.aws/credentials的內(nèi)容还最。另外一個卷是個configMap拓轻,它包含ECR注冊的endpoint扶叉。
{
"credHelpers": {
"<your-aws-account-id>.dkr.ecr.eu-central-1.amazonaws.com": "ecr-login"
}
}
agent的選項參數(shù):
-
label
字符串類型枣氧。此參數(shù)適用于node达吞,docker酪劫,dockerfile覆糟,而且在ndoe中是必輸參數(shù)滩字。
-
customWorkspace
字符串類型麦箍。在自定義工作空間目錄中運行此pipeline流水線而不是使用默認的内列』扒疲可以是相對路徑(相對于運行節(jié)點工作空間的根目錄)也可以是絕對路徑交排。此參數(shù)適用于node埃篓,docker架专,dockerfile想邦。
示例:
agent { node { label 'my-defined-label' customWorkspace '/some/other/path' } }
-
reuseNode
布爾值類型丧没,默認false呕童。此參數(shù)適用于docker和dockerfile夺饲, 且只在stage代理中有效往声。當設置為true時烁挟,則在pipeline的全局agent節(jié)點中運行容器撼嗓,并且是在同一個工作空間中運行而不是在一個全新的節(jié)點中運行且警。
-
args
字符串類型斑芜。適用于docker和dockerfile,用于設置docker run參數(shù)醇王。
示例:
pipeline { agent { docker 'maven:3.8.1-adoptopenjdk-11' } stages { stage('Example Build') { steps { sh 'mvn -B clean verify' } } } }
2. post
定義附加steps在整個pipeline流水線或某個stage執(zhí)行完之后運行寓娩。post可以定義在pipeline的最外層或某個stage里棘伴, 如果定義在最外層則表示這個pipeline執(zhí)行完之后運行焊夸,如果在stage里則表示該stage執(zhí)行完后運行淳地。
post的執(zhí)行條件場景包括:
-
always
不管pipeline或stage的執(zhí)行結果狀態(tài),總會執(zhí)行的steps遣钳。
-
changed
只有在pipeline或stage的執(zhí)行結果狀態(tài)與前一次執(zhí)行相比發(fā)生改變時執(zhí)行蕴茴。
-
fixed
當前pipeline或stage執(zhí)行成功且它的前一次執(zhí)行結果是failure或unstable時執(zhí)行倦淀。
-
regression
當前pipeline或stage執(zhí)行結果是failure, unstable或aborted且它的前一次執(zhí)行成功時執(zhí)行撞叽。
-
aborted
當前pipeline或stage執(zhí)行結果是aborted(人工停止pipeline)時執(zhí)行科展。
-
failure
當前pipeline或stage執(zhí)行結果是失敗時執(zhí)行才睹。
-
success
當前pipeline或stage執(zhí)行結果是成功時執(zhí)行琅攘。
-
unstable
當前pipeline或stage執(zhí)行結果是unstable時執(zhí)行乎澄。
-
unsuccessful
當前pipeline或stage執(zhí)行結果不是成功時執(zhí)行置济。
-
cleanup
在其他所有的post場景腳本都處理完之后執(zhí)行,不管當前pipeline或stage執(zhí)行結果是什么羞酗。
示例:
pipeline {
agent any
stages {
stage('Example') {
steps {
echo 'Hello World'
}
}
}
post {
always {
echo 'I will always say Hello again!'
}
}
}
3. stages(require)
pipeline階段集聲明部分檀轨,至少包含一個或多個stage参萄。
4. stage(atlest one)
構建階段模塊。定義構建階段要做的事情筒溃,每個pipeline流水線至少包含一個stage怜奖。一個stage里有且只有一個steps,
stages,
parallel, 或matrix歪玲。當一個stage內(nèi)嵌在parallel或matrix中的時候读慎,那么該stage就不能再包含parallel或matrix。
示例:
// Declarative //
pipeline {
agent any
stages {
stage('Example') {
steps {
echo 'Hello World'
}
}
}
}
5. steps(require)
steps包含一個或多個可執(zhí)行指令株灸。
6. environment
environment命令用于聲明一系列的鍵值對作為整個pipeline或某個stage指令執(zhí)行的環(huán)境變量慌烧,取決于它定義在pipeline的最外層或stage里。該指令還支持通過credentials()獲取預設的賬號密碼汹粤。
其中支持的credential類型包括:
-
Secret Text
該環(huán)境變量的值將會被設置為Secret Text的內(nèi)容嘱兼。
-
Secret File
該環(huán)境變量的值將會被設置為臨時創(chuàng)建的文件路徑芹壕。
-
Username and password
該環(huán)境變量的值將會被設置為username:password, 并且還會自動創(chuàng)建兩個環(huán)境變量:MYVARNAME_USR和MYVARNAME_PSW。
-
SSH with Private Key
該環(huán)境變量的值將會被設置為臨時創(chuàng)建的ssh key文件路徑斯嚎,并且還會自動創(chuàng)建兩個環(huán)境變量:MYVARNAME_USR和MYVARNAME_PSW堡僻。
示例:
pipeline {
agent any
environment {
CC = 'clang'
}
stages {
stage('Example') {
environment {
AN_ACCESS_KEY = credentials('my-predefined-secret-text')
}
steps {
sh 'printenv'
}
}
}
}
pipeline {
agent any
stages {
stage('Example Username/Password') {
environment {
SERVICE_CREDS = credentials('my-predefined-username-password')
}
steps {
sh 'echo "Service user is $SERVICE_CREDS_USR"'
sh 'echo "Service password is $SERVICE_CREDS_PSW"'
sh 'curl -u $SERVICE_CREDS https://myservice.example.com'
}
}
stage('Example SSH Username with private key') {
environment {
SSH_CREDS = credentials('my-predefined-ssh-creds')
}
steps {
sh 'echo "SSH private key is located at $SSH_CREDS"'
sh 'echo "SSH user is $SSH_CREDS_USR"'
sh 'echo "SSH passphrase is $SSH_CREDS_PSW"'
}
}
}
}
7. options
pipeline流水線選項參數(shù),pipeline流水線提供了一系列的選項參數(shù)固阁。其中也有些由插件提供备燃, 例如timestamps并齐。全局options聲明在最外層, 而寫在stage里的則只在該stage有效且stage options只支持:skipDefaultCheckout测垛,timeout食侮,retry和timestamps。
7.1 buildDiscarder
保存最近構建構建制品和控制臺日志輸出數(shù)量起胰。
示例:
//只保存最近一次構建日志
options {
buildDiscarder(logRotator(numToKeepStr: '1'))
}
7.2 checkoutToSubdirectory
將源碼拉取到工作空間指定的子目錄下效五。
示例:
options {
checkoutToSubdirectory('foo')
}
7.3 disableConcurrentBuilds
不允許同時構建。
示例:
options {
disableConcurrentBuilds()
}
7.4 disableResume
不允許控制器重新開始戒劫。
示例:
options {
disableResume()
}
7.5 newContainerPerStage
與docker或dockerfile代理一起使用巫橄,表示每個stage都將在同一個節(jié)點里啟動新容器運行而不是在同一個容器中運行湘换。
示例:
options {
newContainerPerStage()
}
7.6 overrideIndexTriggers
重寫分支索引觸發(fā)器的處理方式彩倚。如果設置為true帆离, 當分支索引觸發(fā)器在多分支或機構標簽中禁止時,他們將為當前構建開啟。如果設置為false赎瑰, 當分支索引觸發(fā)器在多分支或機構標簽中開啟時,他們將為當前構建禁止鲜漩。
示例:
options {
overrideIndexTriggers(true)
}
7.7 preserveStashes
當stage重新開始時源譬,保存最近構建。
示例:
//保存最近一次完成的構建
options {
preserveStashes()
}
//保存最近5次完成的構建
options {
preserveStashes(buildCount: 5)
}
7.8 quietPeriod
延遲啟動時間孕似,單位:秒踩娘。此設置將重寫默認值。
示例:
options {
quietPeriod(30)
}
7.9 retry(stageable)
失敗重試次數(shù)喉祭。
示例:
options {
retry(3)
}
7.10 skipDefaultCheckout (stageable)
跳過默認代碼拉取。
示例:
options {
skipDefaultCheckout()
}
7.11 skipStagesAfterUnstable
當構建狀態(tài)出現(xiàn)unstable時跳過其他stages泛烙。
示例:
options {
skipStagesAfterUnstable()
}
7.12 timeout(stageable)
設置構建超時時間理卑,超時后自動終止執(zhí)行。
示例:
pipeline {
agent any
options {
timeout(time: 1, unit: 'HOURS')
}
stages {
stage('Example') {
steps {
echo 'Hello World'
}
}
}
}
7.13 timestamps(stageable)
設置日志輸出時間戳蔽氨。
示例:
options {
timestamps()
}
7.14 parallelsAlwaysFailFast
將所有并行stage的failfast設置為true藐唠。
示例:
options {
parallelsAlwaysFailFast()
}
8. parameters
parameters聲明當構建觸發(fā)時用戶要輸入的所有參數(shù)帆疟,steps指令將通過params對象獲取這些參數(shù)。
參數(shù)類型包括:
- string
- text
- booleanParam
- choice
- password
示例:
pipeline {
agent any
parameters {
string(name: 'PERSON', defaultValue: 'Mr Jenkins', description: 'Who should I say hello to?')
text(name: 'BIOGRAPHY', defaultValue: '', description: 'Enter some information about the person')
booleanParam(name: 'TOGGLE', defaultValue: true, description: 'Toggle this value')
choice(name: 'CHOICE', choices: ['One', 'Two', 'Three'], description: 'Pick something')
password(name: 'PASSWORD', defaultValue: 'SECRET', description: 'Enter a password')
}
stages {
stage('Example') {
steps {
echo "Hello ${params.PERSON}"
echo "Biography: ${params.BIOGRAPHY}"
echo "Toggle: ${params.TOGGLE}"
echo "Choice: ${params.CHOICE}"
echo "Password: ${params.PASSWORD}"
}
}
}
}
9. triggers
構建觸發(fā)器宇立。不常用踪宠,一般使用webhooks居多。
-
cron
定時器觸發(fā)泄伪。
示例:
//每隔4小時構建一次 triggers { cron('H */4 * * 1-5') }
-
pollSCM
定時檢查源碼變更觸發(fā)殴蓬。jenkins定時檢查源碼是否變更,如果發(fā)生變更則觸發(fā)構建蟋滴。
示例:
triggers { pollSCM('H */4 * * 1-5') }
-
upstream
上游構建觸發(fā)染厅。當上游構建完成狀態(tài)匹配時觸發(fā)構建。
示例:
triggers { upstream(upstreamProjects: 'job1,job2', threshold: hudson.model.Result.SUCCESS) }
10. tools
聲明需要自動安裝構建所需的工具津函,并設置到PATH環(huán)境變量里肖粮。當agent none時,tools聲明將會被忽略尔苦。
支持自動安裝的工具有:
- jdk
- maven
- gradle
示例:
pipeline {
agent any
tools {
maven 'apache-maven-3.0.1'
}
stages {
stage('Example') {
steps {
sh 'mvn --version'
}
}
}
}
11. input (stage only)
stage參數(shù)輸入指令涩馆。在進入agent模塊和when條件判斷之前,stage將會被暫停并彈出輸入對話框允坚,直到用戶輸入可用參數(shù)后stage才會繼續(xù)執(zhí)行魂那。所有輸入的參數(shù)在余下的stage指令當中都可以通過環(huán)境變量獲取。
input配置選項:
-
messgae (必輸)
提示信息稠项。
-
id
唯一標識涯雅,默認使用該stage名稱。
-
ok
“OK”按鈕名稱展运。
-
submitter
以","分割的用戶或外部組的列表活逆,定義誰可以提交這個輸入項,默認所有人拗胜。
-
submitterParameter
設置submitter的環(huán)境變量名稱蔗候。
-
parameters
配置需要輸入的參數(shù)。
示例:
pipeline {
agent any
stages {
stage('Example') {
input {
message "Should we continue?"
ok "Yes, we should."
submitter "alice,bob"
parameters {
string(name: 'PERSON', defaultValue: 'Mr Jenkins', description: 'Who should I say hello to?')
}
}
steps {
echo "Hello, ${PERSON}, nice to meet you."
}
}
}
}
12. when (stage only)
when命令通過設定的條件判斷決定pipeline流水線的當前stage是否執(zhí)行埂软, when命令至少包含一個條件判斷锈遥。如果when包含多個條件判斷,那么當且僅當所有條件判斷都為true時勘畔,當前stage才會被執(zhí)行迷殿。正常情況下when判斷時在agent,input咖杂,options命令之后才執(zhí)行的庆寺,但是可以通過beforeAgent,beforeInput诉字,beforeOptions參數(shù)來設置提前執(zhí)行懦尝。
示例:
pipeline {
agent none
stages {
stage('Example Build') {
steps {
echo 'Hello World'
}
}
stage('Example Deploy') {
agent {
label "some-label"
}
when {
beforeAgent true
beforeInput true
beforeOptions true
branch 'production'
}
steps {
echo 'Deploying'
}
}
}
}
12.1 branch
只使用于多分支結構流水線知纷。當構建分支匹配給定的分支或正則表達式時為true。
匹配規(guī)則:
-
EQUALS
字符串比較陵霉。
-
GLOB
ANT通配符琅轧。
-
REGEXP
正則表達式。
示例:
when {
branch 'master'
}
when {
branch pattern: "release-\\d+", comparator: "REGEXP"
}
12.2 buildingTag
當構建一個版本標簽時為true踊挠。
when {
buildingTag()
}
12.3 changelog
當SCM的變更日志匹配給定的正則表達式時為true乍桂。
when {
changelog '.*^\\[DEPENDENCY\\] .+$'
}
12.4 changeset
當SCM變更集包含一個或以上文件匹配給定的文件路徑表達式時為true。
匹配規(guī)則:
-
EQUALS
字符串比較效床。
-
GLOB
ANT通配符睹酌。
-
REGEXP
正則表達式。
通過caseSensitive參數(shù)設置是否區(qū)分大小寫剩檀。
示例:
when {
changeset "**/*.js"
}
when {
changeset pattern: ".TEST\\.java", comparator: "REGEXP"
}
or when {
changeset pattern: "*/*TEST.java", caseSensitive: true
}
12.5 changeRequest
當因SCM發(fā)生變更請求(aka憋沿,GitHub and Bitbucket:Pull Request,GitLab:Merge Request沪猴, Gerrit: Change Request)而構建時為true辐啄。可添加過濾屬性运嗜,來篩選符合條件的變更請求:
- id
- target
- branch
- fork
- url
- title
- author
- authorDisplayName
- authorEmail
過濾屬性匹配規(guī)則:
-
EQUALS
字符串比較壶辜。
-
GLOB
ANT通配符。
-
REGEXP
正則表達式担租。
示例:
when {
changeRequest()
}
when {
changeRequest target: 'master'
}
when {
changeRequest authorEmail: "[\\w_-.]+@example.com", comparator: 'REGEXP'
}
12.6 environment
當某個環(huán)境變量值等于給定值時為true砸民。
示例:
hen {
environment name: 'DEPLOY_TO', value: 'production'
}
12.7 equals
當實際值等于期望值時為true。
示例:
when {
equals expected: 2, actual: currentBuild.number
}
12.8 expression
當給定的groovy表達式返回值為true翩活。如果返回值時字符串那么當返回為null時為false,其他字符串都表示為true便贵。
示例:
when {
expression {
return params.DEBUG_BUILD
}
}
12.9 tag
當TAG_NAME環(huán)境變量匹配給定正則表達式時為true菠镇。如果表達式為空則只要TAG_NAME環(huán)境變量存在則為true。
匹配規(guī)則:
-
EQUALS
字符串比較承璃。
-
GLOB
ANT通配符利耍。
-
REGEXP
正則表達式。
示例:
when {
tag "release-*"
}
when {
tag pattern: "release-\\d+", comparator: "REGEXP"
}
12.10 not
當內(nèi)嵌條件為true時盔粹。
示例:
when {
not {
branch 'master'
}
}
12.11 allOf
當所有內(nèi)嵌條件都為true時隘梨。
示例:
when {
allOf {
branch 'master';
environment name: 'DEPLOY_TO', value: 'production'
}
}
12.12 anyOf
當任意內(nèi)嵌條件為true時。
示例:
when {
anyOf {
branch 'master'; branch 'staging'
}
}
12.13 triggeredBy
當構建由給定觸發(fā)時為true舷嗡。
示例:
when { triggeredBy 'SCMTrigger' }
when { triggeredBy 'TimerTrigger' }
when { triggeredBy 'UpstreamCause' }
when { triggeredBy cause: "UserIdCause", detail: "vlinde" }
13. parallel
聲明并行執(zhí)行的stage轴猎。通過在包含parallel的stage里設置failFast true,當其中一個并行stage執(zhí)行失敗時強制終止其他并行stage进萄。也可以在options里做全局設置parallelsAlwaysFailFast()捻脖。
示例:
pipeline {
agent any
options {
parallelsAlwaysFailFast()
}
stages {
stage('Non-Parallel Stage') {
steps {
echo 'This stage will be executed first.'
}
}
stage('Parallel Stage') {
when {
branch 'master'
}
//failFast true
parallel {
stage('Branch A') {
agent {
label "for-branch-a"
}
steps {
echo "On Branch A"
}
}
stage('Branch B') {
agent {
label "for-branch-b"
}
steps {
echo "On Branch B"
}
}
stage('Branch C') {
agent {
label "for-branch-c"
}
stages {
stage('Nested 1') {
steps {
echo "In stage Nested 1 within Branch C"
}
}
stage('Nested 2') {
steps {
echo "In stage Nested 2 within Branch C"
}
}
}
}
}
}
}
}
14. matrix
按name-value定義的命名空間矩陣锐峭,可在stage里使用定義并行任務。matrix必需包含一個axes和一個stages可婶。failFast和parallelsAlwaysFailFast()也使用于matrix沿癞。
-
axes
每一個axes必需包含一個或以上axis
-
axis
每個axis包含一個name和一個values列表,所有axies中的values列表彼此組合產(chǎn)生命名空間cell矛渴。stages將按循序在各個cell中被執(zhí)行椎扬。每個命名空間的name-value鍵值對將自動創(chuàng)建對應的環(huán)境變量。
-
excludes
按命name-value名空間移除不需要執(zhí)行的cell具温。當移除的命名空間cell列表很長時可以使用notValues替代values蚕涤。
每個cell中仍然可以使用以下這些命令, 在matrix最外層聲明:
- agent
- environment
- input
- options
- post
- tools
- when
示例:
pipeline {
parameters {
choice(name: 'PLATFORM_FILTER', choices: ['all', 'linux', 'windows', 'mac'], description: 'Run on specific platform')
}
agent none
stages {
stage('BuildAndTest') {
matrix {
agent {
label "${PLATFORM}-agent"
}
when { anyOf {
expression { params.PLATFORM_FILTER == 'all' }
expression { params.PLATFORM_FILTER == env.PLATFORM }
} }
axes {
axis {
name 'PLATFORM'
values 'linux', 'windows', 'mac'
}
axis {
name 'BROWSER'
values 'firefox', 'chrome', 'safari', 'edge'
}
}
excludes {
exclude {
axis {
name 'PLATFORM'
values 'linux'
}
axis {
name 'BROWSER'
values 'safari'
}
}
exclude {
axis {
name 'PLATFORM'
notValues 'windows'
}
axis {
name 'BROWSER'
values 'edge'
}
}
}
stages {
stage('Build') {
steps {
echo "Do Build for ${PLATFORM} - ${BROWSER}"
}
}
stage('Test') {
steps {
echo "Do Test for ${PLATFORM} - ${BROWSER}"
}
}
}
}
}
}
}
15. script
在steps里使用腳本pipeline代碼段。
示例:
pipeline {
agent any
stages {
stage('Example') {
steps {
echo 'Hello World'
script {
def browsers = ['chrome', 'firefox']
for (int i = 0; i < browsers.size(); ++i) {
echo "Testing the ${browsers[i]} browser"
}
}
}
}
}
}
二. 腳本式流水線(Scripted Pipeline)
基于groovy的腳本桂躏,相對于聲明式pipeline钻趋,腳本式pipeline表達能力更強更有彈性。
示例:
node {
stage('Example') {
try {
sh 'exit 1'
}
catch (exc) {
echo 'Something failed, I should sound the klaxons!'
throw
}
}
}