Skip to content

Instantly share code, notes, and snippets.

@thorntonrose
Last active August 9, 2022 15:34
Show Gist options
  • Save thorntonrose/5f80a9b06b4ccbdd2f3c5380df73b619 to your computer and use it in GitHub Desktop.
Save thorntonrose/5f80a9b06b4ccbdd2f3c5380df73b619 to your computer and use it in GitHub Desktop.
Jenkins scripts

get secret text:

echo withCredentials([string(credentialsId: "<id>", variable: "s")]) { s }

get username and password:

println withCredentials([usernamePassword(credentialsId: "<id>", usernameVariable: "u", passwordVariable: "p")]) { [u, p] }

delete jobs in view:

Jenkins.instance.getView("<view>").items.each { item ->
    println "delete: ${item.name} ..."
    item.delete()
}

kill zombie job:

Jenkins.instance.getItemByFullName("<name>").getBuildByNumber(<number>).finish(hudson.model.Result.ABORTED,
   new java.io.IOException("Aborting build"))

disable jobs:

Jenkins.instance.getItemByFullName("<name>").allJobs[0].disabled = <true|false>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment