This is our Jenkins shared library method to run waitForQualityGate. Could also be inside a script tag in the pipeline. The logMessage and saveStatus methods are our own logging interface:
sleep 10 // wait to ensure all sonar files are written to the local disk
try {
def source = gv.workspaceRootSrc
dir (gv.workspaceRootSrc) {
withSonarQubeEnv ('SonarQube') {
// Wait for Quality Gate and put status into globalVariables
gv.qualityGateStatus = waitForQualityGate().status
}
if (gv.qualityGateStatus == 'OK') {
// Passed Quality Gate
logMessage message: "[WFGG] Quality Gate Passed", messageLevel: 'INFO', globalVariables: gv
saveStatus step:"Quality Gate", task: 'Gate', level: 'Pass', jobStatus: 'SUCCESS', message: "Quality Gate Passed", globalVariables: gv
}
else {
// qualityGateStatus='ERROR' - failed Quality Gate
logMessage message: "[WFGG] Quality Gate Failed", messageLevel: 'INFO', globalVariables: gv
saveStatus step:"Quality Gate", task: 'Gate', level: 'Fail', jobStatus: 'UNSTABLE', message: "Quality Gate Failed", globalVariables: gv
}
}
}
catch (err) {
gv.qualityGateStatus = 'ERROR'
logMessage message: "[WFQG] Wait for Quality Gate Error ($err)", messageLevel: 'INFO', globalVariables: gv
saveStatus step:"Quality Gate", task: 'Wait', level: 'Fail', jobStatus: 'UNSTABLE', message: "Wait for Quality Gate Error ($err)", globalVariables: gv
}
I tried using your method, but Jenkins swears at gv prefix and what workspaceRootSrc means.
can you tell me how I can use this in a pipeline script block?
Sorry, gv is a global variable we def at the top of the pipeline and use to hold variables that need to persist between stages. workspaceRootSrc is the folder where the source code resides.