karthikeayan
karthikeayan

Reputation: 5000

How to restrict a agent in Jenkins to run only one job?

I have a Jenkins master without any extra agents. My Jenkins server is having more than 100 jobs and all of them are checked into source control as a Jenkinsfile.

All the Jenkinsfile contains the below at the begging of the file,

agent any

Now, I want to add one agent to the master and create one job. This newly created job has to run only on the newly added agent machine.

We can restrict a job in Jenkins to run on a particular agent, but in that case I have to modify my all 100 Jenkinsfile to make them run only on master.

Is there a way in Jenkins we can restrict an agent to run a particular job? So that I don't need to modify all the 100 Jenkinsfile.

Upvotes: 0

Views: 2291

Answers (1)

hhami
hhami

Reputation: 176

Hopefully I understand you correctly...

You can add a label to your new job, and have the new node set to Only build jobs with label expressions matching this node... then add the same label to that node and it will only execute jobs matching that.

Upvotes: 1

Related Questions