Issue
thanks in advance for the help.
For our project, for which we use Jenkins, I'm working on a shared library to house all methods for our different pipelines (3 different ones). Currently I'm facing an issue, that I don't really know how to solve.
I configured the jenkins-mattermost-plugin for the project. Ideally, I'd like to create one method for the post
task in Jenkins that takes currentBuild.currentResult
as an argument and returns the corresponding condition block and its message.
Ex:
- if success:
success {
mattermostSend(...success build notification)
}
}
- if failure:
failure {
mattermostSend(...failure build notification)
}
}
- etc.
The problem is not writing the method itself, but when to call it in the pipeline.
I can't call it in a stage
block, not without any block wrapper.
I hope this makes sense what I'm trying to say.
Solution
You can call the function in always post-condition:
post {
always {
mattermostSend("${currentBuild.currentResult}")
}
}
Then inside mattermostSend create condition which depending on the build result will send the required message.
Answered By - Pamela Sarkisyan
Answer Checked By - Marilyn (JavaFixing Volunteer)