I wish to get the latest status of a separate Jenkins job Backup_Precheck
in my current Pipeline script.
Below is my pipeline script.
import groovy.json.JsonSlurper
pipeline
{
agent any
stages {
stage('check Job Backup_Precheck status'){
steps {
script{
if(checkStatus() == "RUNNING" ){
timeout(time: 60, unit: 'MINUTES') {
waitUntil {
def status = checkStatus()
return (status == "SUCCESS" || status == "FAILURE" || status == "UNSTABLE" || status == "ABORTED")
}
}
}
if( checkStatus() != "SUCCESS" ){
error('Stopping Job Weekend_Backup becuase job Backup_Precheck is not successful.')
} else {
echo 'Triggering ansible backup automation'
} // script end
} //steps ends here
} // stage ends here
stage('Hello') {
steps { echo 'Hello World'}
}
} //step closes
}
def checkStatus() {
def statusUrl = httpRequest "https://portal.myshop.com:9043/job/Backup_Precheck/lastBuild/api/json"
def statusJson = new JsonSlurper().parseText(statusUrl.getContent())
return statusJson['result']
}
I get the below error in the jenkins console logs:
[Pipeline] { (Hello) Stage "Hello" skipped due to earlier failure(s) [Pipeline] } [Pipeline] // stage [Pipeline] } [Pipeline] // node [Pipeline] End of Pipeline java.lang.NoSuchMethodError: No such DSL method 'httpRequest' found among steps [ansiColor, ansiblePlaybook, ansibleTower, ansibleTowerProjectRevision, ansibleTowerProjectSync, ansibleVault, archive, bat, build, catchError, checkout, deleteDir, dir, dockerFingerprintFrom, dockerFingerprintRun, dockerNode, echo, emailext, emailextrecipients, envVarsForTool, error, fileExists, findBuildScans, getContext, git, input, isUnix, junit, library, libraryResource, load, lock, mail, milestone, node, parallel, powershell, properties, publishHTML, pwd, pwsh, readFile, readTrusted, resolveScm, retry, script, sh, sleep, stage, stash, step, svn, task, timeout, tm, tool, unarchive, unstable, unstash, validateDeclarativePipeline, waitUntil, warnError, withContext, withCredentials, withDockerConta
I understand that i may need me to install HTTP Request Plugin inorder to resolve the above.
However, can't I get the latest status of a job without having to depend on the HTTP Request Plugin
? If so, kindly guide me.