Created
December 22, 2018 12:18
-
-
Save ansig/d7edafe38fbfc13c5b3cd15351849804 to your computer and use it in GitHub Desktop.
Jenkins init script to add LockableResources specified in a config file (specified in INIT_JENKINS_CONFIG var)
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
@Grab('org.yaml:snakeyaml:1.17') | |
import org.yaml.snakeyaml.Yaml | |
def lockableResourcesConfigFile = new File("${System.getenv('INIT_JENKINS_CONFIG')}/lockableResources.yml") | |
if (lockableResourcesConfigFile.exists()) { | |
println "INFO: Adding LockableResources from configuration: ${lockableResourcesConfigFile.absolutePath}" | |
Yaml parser = new Yaml() | |
def lockableResourcesConfig = parser.load(lockableResourcesConfigFile.text) | |
def manager = org.jenkins.plugins.lockableresources.LockableResourcesManager.get() | |
lockableResourcesConfig.resources.each { | |
println "INFO: Adding: ${it}" | |
manager.createResource(it.name) | |
def resource = manager.fromName(it.name) | |
if (it.description) { | |
resource.setDescription("${it.description}") | |
} | |
if (it.labels) { | |
resource.setLabels("${it.labels}") | |
} | |
if (it.reservedBy) { | |
resource.setReservedBy("${it.reservedBy}") | |
} | |
} | |
manager.save() | |
println "INFO: Done configuring LockableResources" | |
} else { | |
println "INFO: Did not find ${lockableResourcesConfigFile.absolutePath}, ignoring LockableResources init script" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment