Day 77 โ Remote Triggers in Jenkins


On Day 77 of my DevOps Journey, I explored how to trigger Jenkins jobs remotely. This is a crucial feature in CI/CD pipelines when you want external systems (like GitHub, GitLab, or custom scripts) to start Jenkins jobs automatically without manual intervention.
Today, Iโll document the step-by-step guide for setting up remote job triggers using tokens, API tokens, and Jenkins Crumb issuers.
๐ง Step 1 โ Enable Remote Trigger in Job
Go to Jenkins Job โ Configure.
Under Build Triggers, check โ Trigger builds remotely.
Provide a token name (example:
testtoken
).Save the configuration.
Jenkins generates a Job URL with token:
http://<JENKINS_IP>:8080/job/<JOB_NAME>/build?token=testtoken
๐ง Step 2 โ Generate API Token for User
Click your username (top right corner in Jenkins).
Select Configure โ API Token โ Generate.
Save the generated API token securely.
Example: admin:116ce8f1ae914b477d0c74a68ffcc9777c
๐ง Step 3 โ Generate Jenkins Crumb
Jenkins requires a crumb (CSRF protection token) for API requests.
Install
wget
(on Git Bash for Windows).
Place the binary inc:/program files/Git/mingw64/bin
.Run this command (replace with your username, password, Jenkins URL):
wget -q --auth-no-challenge --user username --password password \ --output-document - \ 'http://<JENKINS_IP>:8080/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,":",//crumb)'
Example output:
Jenkins-Crumb:8cb80f4f56d6d35c2121a1cf35b7b501
๐ง Step 4 โ Trigger Jenkins Job via cURL
Now we have:
Jenkins Job URL with token
API Token
Crumb
Use this command:
curl -I -X POST \
http://username:APITOKEN@<JENKINS_IP>:8080/job/<JOB_NAME>/build?token=TOKENNAME \
-H "Jenkins-Crumb:CRUMB"
โ Example:
curl -I -X POST \
http://admin:110305ffb46e298491ae082236301bde8e@52.15.216.180:8080/job/vprofile-Code-Analysis/build?token=testtoken \
-H "Jenkins-Crumb:8cb80f4f56d6d35c2121a1cf35b7b501"
๐ฏ Why This Is Important
Enables automation between services (GitHub โ Jenkins, monitoring alerts โ Jenkins, etc.).
Provides security with tokens and crumbs.
Makes Jenkins more integrated with external systems.
๐ Key Takeaways
Always secure your tokens โ never expose them in plaintext.
Remote triggers are powerful for event-driven CI/CD pipelines.
API tokens + crumbs ensure both authentication and protection from CSRF attacks.
Subscribe to my newsletter
Read articles from Shaharyar Shakir directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
