While building the Job we might want to run our Job only on specific machines (technically environments) for this we can use labels so that this Project (Job) runs only on the machine which has that label we specified.
In this article, we are going to look how to create a Project(Job) that builds only on the machine that has the Label we specify.
Prerequisite
We should have an Agent(Node) added to our Jenkins Controller. (if you want to setup one checkout my article here
Creating Project
In the Jenkins Dashboard click New Item.
Enter the name for the New Item.
Give the description for the Project and select Restrict where this project can be run checkbox and enter the Label of the machine where we need to run this Job.
I have an Ubuntu Node added to the Jenkins Controller with the label "ubuntu". So, I made this project to run only on that machine by giving that label.
Now scroll down and Add build step
I have selected Execute shell since I am gonna run this project in the Linux machine(Ubuntu).
pwd - prints the current working dir
uname - gives the OS of the machine
echo "Running this Project on ${NODE_NAME}" - prints the Node name on which this project runs.
echo "Lables of this node: ${NODE_LABELS}" - prints the Labels of that node
NODE_NAME , NODE_LABELS are Jenkins environmental variable.
Click Save. Project is created.
Build Project
Inside the Project's page click Build Now to build the project.
Click on the Build Numbers in the Build History to see the Console Output of that build.
We have successfully created a Project and restricted that project to run only on the machine that has the Label "ubuntu".
Hope you have learned something new here.
Happie Learning :)
Keep Learning!!!
Top comments (0)