I want to define multiple stages in Jenkins declarative pipeline syntax which can continue past any one of them failing. I cannot find any existing questions which are true dupl
I achieved it using post. My requirement was to send out slack notification irrespective of the build status.
@Library('instanceGroups')
import x.z.y.jenkins.libraries.SlackNotifier
def slackHelper = new x.z.y.jenkins.libraries.SlackNotifier(env)
final String projectName = "pomeranian"
final String featureBranchPattern = "f_"
pipeline {
agent any
options { disableConcurrentBuilds() }
stages {
stage('clean') {
steps {
script {
try {
echo 'Current Branch...' + env.BRANCH_NAME
sh 'rm -rf /var/lib/jenkins/.gradle/caches'
sh './gradlew clean'
} catch (e) {
currentBuild.result = 'FAILURE'
slackHelper.buildGenericJobFailureNotificationMessage()
throw e
}
}
}
}
stage('compile') {
steps {
script {
try {
sh "./gradlew compileJava"
} catch (e) {
currentBuild.result = 'FAILURE'
slackHelper.getCompilationFailureSlackNotificationMessage()
throw e
}
}
}
}
stage('test') {
steps {
script {
try {
sh "./gradlew test"
} finally {
junit 'build/test-results/test/*.xml'
slackHelper.getTestStatuses(currentBuild)
slackHelper.buildUnitTestSlackNotificationMessage()
}
}
}
}
stage('publish 2 nexus') {
steps {
script {
// some code
}
}
}
stage('git tagging') {
steps {
script {
// some more code...
}
}
}
post {
always {
script {
slackHelper.finalBuildStatusMessage(currentBuild)
slackSend(channel: '#ci-cd', attachments: slackHelper.getFinalSlackMessage())
}
}
}
}