Forked from danielhpavey/jenkins-pipeline-template.groovy
Created
May 17, 2021 18:54
-
-
Save chrisice/6be8286a7a34352dd385d8f32229e584 to your computer and use it in GitHub Desktop.
Jenkins Pipeline Template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
env.niceName = 'Build Name' | |
pipeline { | |
agent any | |
//agent { label "jenkins-node-1"} | |
triggers { | |
cron () | |
} | |
stages { | |
stage ('Stage Name') { | |
steps { | |
sh 'echo "Hello World"' | |
} | |
} | |
} | |
post { | |
always { | |
cleanWs(cleanWhenAborted: true, cleanWhenFailure: true, cleanWhenNotBuilt: true, cleanWhenSuccess: true, cleanWhenUnstable:true, cleanupMatrixParent: true, deleteDirs: true) | |
} | |
success { | |
slackSend(color: 'good', message: "*${niceName}* pipeline has finished build ${currentBuild.displayName} :white_check_mark:\nResult: ${currentBuild.currentResult}\nRun Duration: ${currentBuild.durationString}\n<${RUN_DISPLAY_URL}|View Build (#${currentBuild.number})> - <${JOB_DISPLAY_URL}|View All Builds>"); | |
} | |
failure { | |
slackSend(channel: "#alert", color: 'danger', message: "*${niceName}* pipeline has failed build ${currentBuild.displayName} :x:\n<${RUN_DISPLAY_URL}|View Build (#${currentBuild.number})> - <${JOB_DISPLAY_URL}|View All Builds>"); | |
emailext body: "${currentBuild.currentResult}: Job ${env.JOB_NAME} build ${env.BUILD_NUMBER}\n\nMore info at: ${RUN_DISPLAY_URL}", | |
recipientProviders: [[$class: 'DevelopersRecipientProvider'], [$class: 'RequesterRecipientProvider']], | |
subject: "Jenkins Build ${currentBuild.currentResult}: Build ${env.BUILD_NUMBER} - Job ${env.JOB_NAME}" | |
} | |
unstable { | |
slackSend(color: 'warning', message: "*${niceName}* pipeline has been marked as unstable after build ${currentBuild.displayName}\n<${RUN_DISPLAY_URL}|View Build (#${currentBuild.number})> - <${JOB_DISPLAY_URL}|View All Builds>"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment