Last active
April 3, 2021 08:31
-
-
Save t3knoid/cae23d005c721b4abd63181db68d38bb to your computer and use it in GitHub Desktop.
A Groovy script that will store the build number of a Jenkins job's last build into a variable
This file contains 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
def address = "http://{jenkinsBase}/job/${jobName}/lastBuild/buildNumber" | |
try { | |
println("${address}") | |
def urlInfo = address.toURL() | |
response = urlInfo.openConnection() | |
if (response.getResponseCode() != 200) { | |
throw new Exception("Unable to connect to " + address) // Throw an exception to get out of loop if response is anything but 200 | |
} | |
buildNum= response.getInputStream().getText() | |
println("buildnum=${buildNum}") | |
} | |
catch (Exception ex) { | |
println (ex.getMessage()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment