Originally published on 2014-05-27; fully revised and updated.
If you need to start Jenkins jobs from scripts, cron, or other automation, you usually do not “log in” interactively. Instead, you authenticate HTTP requests (typically with username + API token) and call Jenkins job endpoints. This guide shows reliable command-line patterns with cURL and wget, plus common failure fixes.

What “login” means for Jenkins CLI and scripts
For scripted access, Jenkins authentication is normally sent with each request. In practice, that means:
- Use a Jenkins username and API token (preferred for scripts).
- Call job endpoints such as
/job/<name>/buildor/job/<name>/buildWithParameters. - Use HTTP
POSTwhen triggering builds.
Command-line trigger workflow
flowchart TD
A[Create API token in Jenkins user settings] --> B[Test authenticated request]
B --> C[POST build endpoint]
C --> D{Build queued?}
D -- yes --> E[Monitor queue or build status]
D -- no --> F[Check credentials permissions and CSRF crumb]
F --> C
Method 1: Trigger Jenkins jobs with cURL
Basic authenticated trigger
curl -X POST "http://jenkins:8080/job/my%20job/build" \
--user "username:api_token"Code language: JavaScript (javascript)
Trigger with delay
curl -X POST "http://server/view/name/job/jobname/build?delay=0sec" \
--user "username:api_token"Code language: JavaScript (javascript)
Trigger a parameterized job
curl -X POST "http://jenkins:8080/job/my-job/buildWithParameters" \
--user "username:api_token" \
--data "ENV=prod" \
--data "VERSION=1.2.3"Code language: JavaScript (javascript)
If CSRF protection blocks POST requests
Some Jenkins setups require a crumb header for POST requests. A common approach is to fetch the crumb, then send it with the build trigger:
CRUMB=$(curl -s --user "username:api_token" \
"http://jenkins:8080/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,\":\",//crumb)")
curl -X POST "http://jenkins:8080/job/my-job/build" \
--user "username:api_token" \
-H "$CRUMB"Code language: JavaScript (javascript)
Method 2: Trigger Jenkins jobs with wget
The original post highlighted a version-specific behavior difference in wget authentication flags.
wget 1.11 style
wget --auth-no-challenge \
--http-user="user" \
--http-password="apiToken" \
"http://jenkins.yourcompany.com/job/your_job/build?token=TOKEN"Code language: JavaScript (javascript)
wget 1.10.x legacy style
wget "http://user:apiToken@jenkins.yourcompany.com/job/your_job/build?token=TOKEN"
wget "http://yourserver/job/MyJobname/build?delay=0sec"Code language: JavaScript (javascript)
cURL vs wget for Jenkins automation
| Tool | Best for | Strengths | Watch-outs |
|---|---|---|---|
| cURL | General Jenkins API automation | Flexible methods, headers, and payload handling | Requires explicit handling for auth headers and possible CSRF crumbs |
| wget | Simple URL-based triggers and legacy scripts | Very simple for basic HTTP calls | Authentication behavior can differ by version; credential-in-URL patterns are less safe |
References and scripted client options
For Groovy, Perl, Java, and broader API patterns, see the original references:
- https://wiki.jenkins-ci.org/display/JENKINS/Authenticating+scripted+clients
- https://wiki.jenkins-ci.org/display/JENKINS/Remote+access+API
Troubleshooting common failures
- 401 Unauthorized: username or API token is wrong, or user has no API access.
- 403 Forbidden: user lacks job permissions, or CSRF crumb is required but missing.
- 404 Not Found: job path is wrong (including folder/view path issues).
- Request succeeds but no build appears: verify the endpoint (
buildvsbuildWithParameters) and required parameters.
Best practices
- Use API tokens instead of account passwords in scripts.
- Avoid embedding credentials directly in URLs when possible.
- Store tokens in environment variables or a secret manager, not in plain-text scripts.
- Use least-privilege Jenkins users dedicated to automation.
- Log HTTP status codes in automation so failures are detectable and actionable.
I’m Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms.
I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.
Find Trusted Cardiac Hospitals
Compare heart hospitals by city and services — all in one place.
Explore Hospitals