What I'm trying to do is integrate with GitHib Checks API so I need to be able to post three types of events to GitHub.
1) When build started (which I did as a pipeline step plugin - gitHubCheckRunBegin())
2) When build was successful (which I did as a pipeline step plugin - gitHubCheckRunEnd())
3) When build fails. Here I would need to get the output of the stage the failed to be able to send that to GitHub.
For #3 I did as you suggested from @Ullrich link as a block scoped function which seems perfect.
Dos it make sense? Is it ok the way it was done?
And I'm planing to use this like:
node {
def cfg = [
'stuff': 'stuff',
...
]
stage('Cleanup') {
cleanWs()
}
stage('Git') {
git(...)
}
stage('CheckRun_Begin') {
gitHubCheckRunBegin(cfg)
}
stage('Yarn') {
withGitHubCheckRun(cfg) {
sh(...)
}
}
stage('Build') {
withGitHubCheckRun(cfg) {
sh(...)
}
}
stage('CheckRun_End') {
gitHubCheckRunEnd(cfg)
}
}
So at start gitHubCheckRunBegin makes call to GitHub api to start the check, gitHubCheckRunEnd will make call to GitHub api to end the check successfully (assuming the job gets there).
And if any step fails then the withGitHubCheckRun will catch that stage output and push it the GitHub API