使用新语法使用声明性管道,例如:
pipeline { agent any stages { stage('Test') { steps { sh 'echo "Fail!"; exit 1' } } } post { always { echo 'This will always run' } success { echo 'This will run only if successful' } failure { mail bcc: '', body: "<b>Example</b><br>n<br>Project: ${env.JOB_NAME} <br>Build Number: ${env.BUILD_NUMBER} <br> URL de build: ${env.BUILD_URL}", cc: '', charset: 'UTF-8', from: '', mimeType: 'text/html', replyTo: '', subject: "ERROR CI: Project name -> ${env.JOB_NAME}", to: "foo@foomail.com"; } unstable { echo 'This will run only if the run was marked as unstable' } changed { echo 'This will run only if the state of the Pipeline has changed' echo 'For example, if the Pipeline was previously failing but is now successful' } }}您可以在詹金斯官方网站上找到更多信息:
https://jenkins.io/doc/pipeline/tour/running-multiple-
steps/
请注意,这种新语法使您的管道更具可读性,逻辑性和可维护性。



