Created
November 16, 2018 13:49
-
-
Save Sysa/6b452a320eb4b9004b407f1b1866ba59 to your computer and use it in GitHub Desktop.
jenkins get last successful build parameters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//jenkins get last successful build parameters | |
node("master"){ | |
//get `branch` parameter of jenkins build | |
String sh_curl_result = sh(script: "curl -u your_jenkins_user:your_secret_API_key 'http://jenkinsInstance:8080/job/Project/job/job_name_deploy_all/lastSuccessfulBuild/api/xml?tree=actions\\[parameters\\[name,value\\]\\]&xpath=/workflowRun/action/parameter\\[name=%22Branch%22\\]/value'", returnStdout: true).trim() | |
println sh_curl_result | |
//string() is not supported by jenkins xpath XML api, so need to cut `value` tags it via regex: | |
result = (sh_curl_result =~ /(?<=>).*(?=<)/)[0] | |
println result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment