Last active
May 1, 2023 15:48
-
-
Save msutter/6533f2b0491ffefee2c7ca7c05a80d49 to your computer and use it in GitHub Desktop.
jenkins master node executors and restriction
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
#!groovy | |
import jenkins.model.* | |
import hudson.model.* | |
import hudson.slaves.* | |
import com.synopsys.arc.jenkinsci.plugins.jobrestrictions.nodes.JobRestrictionProperty; | |
import com.synopsys.arc.jenkinsci.plugins.jobrestrictions.restrictions.job.RegexNameRestriction; | |
import com.synopsys.arc.jenkinsci.plugins.jobrestrictions.util.GroupSelector; | |
// Set nummber of executors | |
def instance = Jenkins.getInstance() | |
instance.setNumExecutors(1) | |
instance.save() | |
// Restrict master node executor access | |
def regularSlaves = Jenkins.instance.computers.grep{ | |
it.class.superclass?.simpleName != 'AbstractCloudComputer' | |
} | |
def masterComputer = regularSlaves.find { it.displayName =~ "master" } | |
def regex = "^admin.*" | |
RegexNameRestriction regexRestr = new RegexNameRestriction(regex, false ); | |
JobRestrictionProperty jobrestrict = new JobRestrictionProperty(regexRestr); | |
masterNode = masterComputer.getNode() | |
masterNode.getNodeProperties().add(jobrestrict) | |
masterNode.save() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment