Hello Readers! We actually know various methods to trigger a Jenkins job but in this blog we will see how we can easily trigger a Jenkins job via curl command remotely. This is very quick and simple so let’s see.
Curl stands for client URL. It is a command-line tool that we can easily use to transfer data to and from a server. It lets us talk to a server by specifying the location (in the form of a URL) and the data you want to send. We will use curl to send API requests.
Why do we need to trigger a job remotely?
Jenkins is well known for its flexibility. It supports a wide range of configurations through its plugins. There are various triggering options found in Jenkins. It can be ‘Build periodically’, ‘GitHub hook trigger’, ‘trigger build remotely’, and many more. Jenkins also gives us flexibility by which we can easily trigger a job from the script, command line.
So, Let’s Get Started!
There are three main steps needed to perform:
- Create an authentication token in Jenkins
- Configure a job to trigger from remote in Jenkins
- Trigger the jenkins job via curl
Create an authentication token in Jenkins:
To create an authentication token is quite simple you only need to follow these steps:
After that on that page
- Clickon “Add new Token” button.
- Add the token name and click on the “Generate”
- Copy the token name for further use.
Configure a job to trigger from remote in Jenkins
You can create a new FreeStyle job or you can use the previous one. Move to configuration -> Build Triggers sections and check the “Trigger builds remotely(e.g., from scripts)” option and paste the token name there.
Trigger the Jenkins job via curl
Now it’s time to trigger the job using CURL. Here you will replace the name of the job by your job name and token by your token.
We can see now the output if its triggered:
It’s all successfully done!
In this blog we have seen how in a few easy steps we can trigger a jenkins job remotely via curl. Thanks for being with me till the end. If you find this blog helpful do share with your friends.