简体   繁体   中英

Jenkins Pipeline: Check status of another project last build

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM