Skip to content

Instantly share code, notes, and snippets.

@msutter
Last active May 1, 2023 15:48
Show Gist options
  • Save msutter/6533f2b0491ffefee2c7ca7c05a80d49 to your computer and use it in GitHub Desktop.
Save msutter/6533f2b0491ffefee2c7ca7c05a80d49 to your computer and use it in GitHub Desktop.
jenkins master node executors and restriction
#!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