W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
由于post Pipeline的部分保證在Pipeline執(zhí)行結(jié)束時運行,因此我們可以添加一些通知或其他步驟來執(zhí)行定稿,通知或其他Pipeline末端任務(wù)。
Jenkinsfile (Declarative Pipeline)
pipeline {
agent any
stages {
stage('No-op') {
steps {
sh 'ls'
}
}
}
post {
always {
echo 'One way or another, I have finished'
deleteDir() /* clean up our workspace */
}
success {
echo 'I succeeeded!'
}
unstable {
echo 'I am unstable :/'
}
failure {
echo 'I failed :('
}
changed {
echo 'Things were different before...'
}
}
}
Toggle Scripted Pipeline (Advanced)
Jenkinsfile (Scripted Pipeline)
node {
try {
stage('No-op') {
sh 'ls'
}
}
}
catch (exc) {
echo 'I failed'
}
finally {
if (currentBuild.result == 'UNSTABLE') {
echo 'I am unstable :/'
} else {
echo 'One way or another, I have finished'
}
}
有很多方法可以發(fā)送通知,下面是一些演示如何將有關(guān)Pipeline的通知發(fā)送到電子郵件,Hipchat房間或Slack頻道的片段。
post {
failure {
mail to: 'team@example.com',
subject: "Failed Pipeline: ${currentBuild.fullDisplayName}",
body: "Something is wrong with ${env.BUILD_URL}"
}
}
post {
failure {
hipchatSend message: "Attention @here ${env.JOB_NAME} #${env.BUILD_NUMBER} has failed.",
color: 'RED'
}
}
post {
success {
slackSend channel: '#ops-room',
color: 'good',
message: "The pipeline ${currentBuild.fullDisplayName} completed successfully."
}
}
現(xiàn)在,當(dāng)事情出現(xiàn)故障,不穩(wěn)定或甚至成功時,我們可以通過令人興奮的部分完成我們的持續(xù)交付流程:shipping!好了現(xiàn)在讓我們來看看下一節(jié):Jenkins部署
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: