Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/bin/env groovy
class Constants {
static final MAVEN_LOCAL_REPO_DIR = 'repository'
static final WORKSPACE_DIR = 'build'
}
/**
* https://jenkins.io/doc/book/pipeline-as-code/
* http://javadoc.jenkins.io/plugin/workflow-basic-steps/
* */
def numBuilds = env.BRANCH_NAME == 'master' ? '10' : '3'
def keepBuildsDays = env.BRANCH_NAME == 'master' ? '30' : '7'
properties(
[
buildDiscarder(logRotator(artifactDaysToKeepStr: keepBuildsDays, artifactNumToKeepStr: numBuilds, daysToKeepStr: keepBuildsDays, numToKeepStr: numBuilds))
, disableConcurrentBuilds()
, compressBuildLog()
]
)
timeout(time: 90, unit: 'MINUTES') {
node('master') {
ansiColor('xterm') {
timestamps {
try {
if (!isUnix()) {
abortBuild('Jenkins CI should run on Ubuntu!')
}
currentBuild.result = 'SUCCESS'
} catch (e) {
currentBuild.result = 'FAILURE'
println e
throw e
} finally {
println(isCurrentBuildSuccessful() ? 'The build is successful.' : 'The build has failed.')
dir("${Constants.WORKSPACE_DIR}") {
emailext(body: "See ${env.BUILD_URL}", recipientProviders: [[$class: 'DevelopersRecipientProvider'], [$class: 'CulpritsRecipientProvider'], [$class: 'FailingTestSuspectsRecipientProvider'], [$class: 'FirstFailingBuildSuspectsRecipientProvider']], subject: "${env.JOB_NAME} - build ${env.BUILD_DISPLAY_NAME} - ${currentBuild.result}", attachLog: true, from: 'smtp.WildFly@scheidt-bachmann.sk')
}
/*
* http://javadoc.jenkins-ci.org/hudson/model/Result.html
* changed, failure, success, unstable, aborted
* changed: currentBuild.result ==
* failure: currentBuild.result == 'FAILURE'
* success: currentBuild.result == 'SUCCESS' or null
* unstable: currentBuild.result == 'UNSTABLE'
* aborted: currentBuild.result == 'ABORTED'
* 'NOT_BUILT'
*/
stage('workspace cleanup') {
if (isTrunk() && !isCurrentBuildAborted()) {
sh "rm -rf ./${Constants.MAVEN_LOCAL_REPO_DIR}/com/scheidtbachmann"
sh "rm -rf ./${Constants.WORKSPACE_DIR}"
} else {
// https://github.com/jenkinsci/ws-cleanup-plugin/blob/master/src/main/java/hudson/plugins/ws_cleanup/WsCleanup.java
cleanWs()
}
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.