Created
February 13, 2018 20:52
-
-
Save t3knoid/20480c722d2ef3721dfdb71f5f3e3781 to your computer and use it in GitHub Desktop.
Jenkins groovy script to stop a running job
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
// Post to stop a running Jenkins job | |
build = 63 | |
jobName = // Set job name here | |
jlc=JenkinsLocationConfiguration.get() // Get Jenkins base URL from configuration | |
jenkinsBase = jlc.getUrl() | |
addr = "${jenkinsBase}job/${jobName}/${build}/stop" // Stop URL | |
authString = "frefol:d0882d0d535f52cc87f3ac3694d7ad61".getBytes().encodeBase64().toString() // Use authentication token | |
println("${addr}") | |
try { | |
def connection = addr.toURL().openConnection() | |
connection.setRequestProperty( "Authorization", "Basic ${authString}" ) | |
connection.setRequestMethod("POST") // Use post to load URL | |
if( connection.responseCode == 200 ) { | |
println("Build stopped") | |
} else { | |
println "Something bad happened. " | |
println "${connection.responseCode}: ${connection.responseMessage}" | |
} | |
} | |
catch (Exception ex) { | |
println (ex.getMessage()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment