Failback to master agent if other agents arent avaliable

reference
Using a Jenkinsfile, I have 2 agents (master, nodeA).

I prefer my job to run on nodeA. If its not available (its a ec2 instance), i want it to run on master.

Is there a way to declare this in a pipeline? I know there is a feature to prefer an agent or explicity set it as a label but I really want the logic to be in a pipeline.

Hi there,

As a reminder, the term “master” to refer to a controller has been deprecated since 2020. Please refer to On Jenkins Terminology Updates for more details. We request you update your post.

Thanks,
Mark Waite

Pipelines can select their agent based on a label. Label it to use the agent and follow the recommended practice of not enabling an executor on the controller.

If you want an agent on the same host that runs the controller, define an agent that uses a separate account on the same host that runs the controller. Then you can label the job to use either agent. I’m not aware of a way to force Jenkins to prefer one agent label over another for a specific Pipeline job.

The scoring load balancer plugin might be able to help, though it is old enough that I am not confident that it will work with a modern Jenkins controller.

This link doesn’t actually tell OP what to use in place of the discouraged term. It says the team is working on a plan, but there is no alternative clearly defined. I believe the Jenkins UI uses ‘Built-In Node’ to idintify the agent on the main Jenkins server.

Thanks for noting that. How about, “Please refer to the Jenkins glossary” where it says:

Master

A deprecated term, synonymous with Controller.

1 Like