node {stage('Build'){
sh 'make'
archiveArtifacts artifacts:'**/target/*.jar', fingerprint:true}}
测试 stage,(sh ‘make check || true’)确保 sh stage 始终可以看到退出代码
node {/* .. snip .. */stage('Test'){/* `make check` returns non-zero on test failures,
* using `true` to allow the Pipeline to continue nonetheless
*/
sh 'make check || true'
junit '**/target/*.xml'}/* .. snip .. */}
properties([parameters([string(defaultValue:'Hello', description:'How should I greet the world?', name:'Greeting')])])
node {
echo "${params.Greeting} World!"}
node {stage('Deploy'){retry(3){
sh './flakey-deploy.sh'}timeout(time:3, unit:'MINUTES'){
sh './health-check.sh'}}}
超时、重试组合使用
node {stage('Deploy'){timeout(time:3, unit:'MINUTES'){retry(5){
sh './flakey-deploy.sh'}}}}
post 使用
node {try{stage('Test'){
sh 'echo "Fail!"; exit 1'}
echo 'This will run only if successful'}catch(e){
echo 'This will run only if failed'// Since we're catching the exception in order to report on it,// we need to re-throw it, to ensure that the build is marked as failedthrow e
}finally{def currentResult = currentBuild.result ?:'SUCCESS'if(currentResult =='UNSTABLE'){
echo 'This will run only if the run was marked as unstable'}def previousResult = currentBuild.previousBuild?.result
if(previousResult != null && previousResult != currentResult){
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'}
echo 'This will always run'}}
在管道中发布 HTML 报告
properties([[$class:'BuildDiscarderProperty',
strategy:[$class:'LogRotator', numToKeepStr:'10']]])
node {
stage ('Build'){// Checkout
checkout scm
// install required gems
sh 'bundle install'// build and run tests with coverage
sh 'bundle exec rake build spec'// Archive the built artifacts
archive includes:'pkg/*.gem'// publish html
publishHTML (target:[
allowMissing:false,
alwaysLinkToLastBuild:false,
keepAll:true,
reportDir:'coverage',
reportFiles:'index.html',
reportName:'RCov Report'])}}