As part of one of my build (ProjectA) I need to copy artifacts from another project (ProjectB). Currently I am taking the "last successful build".
But this poses an issue if the last builds of ProjectB are failing then the current build of ProjectA will receive outdated files.
So I would like ProjectA to receive last build of ProjectB only if this build is successful, otherwise it should fail. For this I need a command to query ProjectB last build status
I found a equivalent command to check the previous build status of the current pipeline, but not for another project. Thanks for your help :)
You can use the following syntax:
import groovy.json.JsonSlurper
def getJobStatus(String jobName){
def request = httpRequest "https://<JENKINS_ADDRESS>/job/${jobName}/lastBuild/api/json"
def requestJson = new JsonSlurper().parseText(request.getContent())
return requestJson['result']
}
See this for example.
Also you can check the httpRequest documentation.