jenkinsci / kubernetes-operator

Kubernetes native Jenkins Operator
https://jenkinsci.github.io/kubernetes-operator
Other
591 stars 231 forks source link

Be able to set the seed-job-agent to "Only build jobs with label expression matching this node" #1014

Open renovate-eika opened 1 month ago

renovate-eika commented 1 month ago

Describe the solution you'd like

The reason behind this is that we have many multibranch pipelines which are pointing to Jenkinsfiles without any requirements of using node labels. We only use labels if they need to use a special node that is not on the "golden path". On the Jenkins server we decide which agents should be used as much as possible.

Describe alternatives you've considered

Since the seed-job is by default labeled/restricted to use "seed-job-agent", I think the agent could be set to only build the jobs with matching labels, or at least an option to set these settings.

I have tested to do this with the following groovy script added to "groovyScripts" without any success:

apiVersion: v1
kind: ConfigMap
metadata:
  name: seed-job-agent
data:
  seed-job-agent.groovy: |2
    import jenkins.model.Jenkins
    import hudson.model.Node.Mode

    def agentName = 'seed-job-agent'
    def newExecutors = 1  

    def agent = Jenkins.instance.getNode(agentName)
    if (agent != null) {
      agent.setNumExecutors(newExecutors)
      agent.setMode(Mode.EXCLUSIVE)
      agent.save()
      println("The number of executors for agent '${agentName}' has been set to ${newExecutors} and configuration saved.")
      Jenkins.instance.reload()
    } 

Additional context

There may be use-cases I haven't thought through