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.
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.
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.