Below is my code, which is part of a groovy script where I created a custom step which executes some closure before running warnings NG and publishes a build badge and feeds the results to gitlab.
Unfortunately, I was not able to get the {{QualityGateStatus, which would have helped me to set the build badge and Gitlab commit status to unstable. There was a method not found error if I remember correctly. I will have to perform some further analysis on this.}}
{code:java} def runWarningsNGStage(String stageName, analysisTool, int newIssuesThreshold = 1, boolean newIssuesUnstable = false, int totalIssuesThreshold = 0, boolean totalIssuesUnstable = false, Closure body) { def buildBadge = addEmbeddableBadgeConfiguration(id: stageName, subject: stageName) stage(stageName) { updateGitlabCommitStatus(name: stageName, state: 'running') buildBadge.setStatus('running')
body()
def foundIssues = scanForIssues(tool: analysisTool) def action = publishIssues(issues: [foundIssues], qualityGates: [[threshold: newIssuesThreshold, type: 'NEW', unstable: newIssuesUnstable], [threshold: totalIssuesThreshold, type: 'TOTAL', unstable: totalIssuesUnstable]])
// TODO: for some reason action.getQualityGateStatus().getResult() does not work, using this result we could set it to unstable as well. def result = action.isSuccessful()
if(result) { buildBadge.setStatus('passing') updateGitlabCommitStatus(name: stageName, state: 'success') } else { buildBadge.setStatus('failing') updateGitlabCommitStatus(name: stageName, state: 'failed') } } } {code} |
|
|