您的位置:首页 > 其它

jenkins学习笔记-5-清理和通知

2017-08-22 09:06 148 查看

清理和通知

由于post是约定在通道的最后部分执行的,我们可以增加一些通知或者其他执行终止、通知的步骤或者其他其他管道终止的任务

 

Jenkinsfile(Declarative Pipeline)

pipeline{

         agentany

         stages{

         stage(‘No-op’){

         sh’ls’

}

}

post{

         always{

         acho ‘oneway or another,I have finished’

         deleteDir()/** clean up our workspace */

}

success{

         echo ‘Isuccessed!’

}

unstable{

         echo ‘I amunstable :/’

}

failure{

         echo ‘Ifailed :(’

}

changed{

         echo‘things were different before …’

}

}

 

}

 

 

Toggle Scripted Pipeline
(高级)
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, Ihave finished'
    }
}
 

 

有很多种发送通知的方式,下面是一个演示如何通过邮件,聊天室,或松弛的管道发送消息的小片段

 

Email

post{

         failure{

         mail to : ‘team@example.com’,

                   subject:”FailedPoleline:${currentBuild.fullDisplayName}”,

                   body:”Something is wrong with${env.Build_url}”

}

}

 

Hipchat

post{

         failure{

         hipchatSend message:”Attention @here${env.JOB_NAME} #${env.BUILD_NUMBER} has failed.”

         color:’RED’

}

}

 

Slack

post{

         success{

         slackSendchannel :’#ops-room’,

                             color :’good’,

                             message:The pipeline ${currentBuild.fullDisplayName}completed successfully”

}

}

 

既然我们的团队成员可以在事务出现失败,不稳定甚至是成功时被通知,那么我们可以通过令人兴奋的部分完成持续交付管道:运送(shipping

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: