Created
November 6, 2019 12:27
-
-
Save marcusphi/d5a5d5769b69627a5169dc440d52a223 to your computer and use it in GitHub Desktop.
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
/** | |
* Clean all non-locked lockable resources from Jenkins config. | |
* | |
* Rationale: When using lock function in pipeline with a dynamic string that will have many values | |
* over time, the Jenkins global configure page is filled with lockable resources. | |
* | |
* @param mailTo String - Comma separated list of email addresses to mail upon error | |
*/ | |
def cleanLockableResources(String mailTo) { | |
try { | |
def res = GlobalConfiguration.all().get(org.jenkins.plugins.lockableresources.LockableResourcesManager.class).resources | |
def unlocked = res.findAll { it -> !it.locked } | |
println "Will remove ${unlocked.size()} lockable resources" | |
res.retainAll {it -> it.locked} | |
} catch (Throwable e) { | |
echo '==== Error mgmt: Do notifications ================' | |
try { | |
mail to: mailTo, | |
subject: "Build ${env.BUILD_DISPLAY_NAME} of ${env.JOB_NAME} failed", | |
body: "Build ${env.BUILD_DISPLAY_NAME} of ${env.JOB_NAME} failed\nBuild: ${env.BUILD_URL}" | |
} catch (Throwable err) { | |
echo 'ERROR: mail failure: ' + err.getMessage() | |
} | |
throw e | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment