MYHOSPITALNOW.COM

Find Trusted Doctors & Hospitals

Discover healthcare providers, compare hospitals, and explore treatment options worldwide.

Free Treatment Quotes • Doctor Search • Hospital Comparison

Find Healthcare Options

www.myhospitalnow.com

Jenkins Command-Line Authentication and Job Triggers with cURL and Wget

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.

Jenkins login and command-line trigger

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>/build or /job/<name>/buildWithParameters.
  • Use HTTP POST when 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

ToolBest forStrengthsWatch-outs
cURLGeneral Jenkins API automationFlexible methods, headers, and payload handlingRequires explicit handling for auth headers and possible CSRF crumbs
wgetSimple URL-based triggers and legacy scriptsVery simple for basic HTTP callsAuthentication 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:

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 (build vs buildWithParameters) 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.

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services — all in one place.

Explore Hospitals
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.

Related Posts

HTTP 404 for DevOps: Root-Cause, Routing, and Prevention Across Edge, Ingress, and App Layers

HTTP 404 errors are simple for users but often complex in distributed systems. This guide shows DevOps teams how to locate the failing layer, apply the right fix, and prevent repeat incidents.

Read More

Common Gateway Interface (CGI): How It Works, Server Requirements, and Basic Setup

CGI is the classic interface that lets a web server execute server-side programs in response to HTTP requests. This revised guide covers CGI fundamentals, server prerequisites, setup checks, and a minimal working example.

Read More

Apache and HTTP Interview Questions: Updated Answers for DevOps Engineers

A modernized Apache and HTTP interview guide with practical, production-focused answers. Includes command comparisons, config examples, and a safe change workflow.

Read More

Building Resilient Web Data Pipelines: How to Handle Rate Limits, Proxy Failures and Infrastructure Outages

A web data collection script can work perfectly during testing and still become unreliable within hours of entering production. A target website may start returning rate limits….

Read More

Best Free, Open-Source & Self-Hosted Synthetic Monitoring, Uptime Monitoring and Health-Check Tools

Monitoring a service is no longer just about asking, “Does port 443 respond?” Modern reliability monitoring may need to confirm that DNS resolves correctly, TLS certificates are…

Read More

Inspect HTTP Requests Online: The Smarter Way to Debug APIs, Webhooks, and Request-Response Traffic

Here’s a polished blog draft you can use. Inspect HTTP Requests Online: The Smarter Way to Debug APIs, Webhooks, and Request-Response Traffic Modern applications rely heavily on…

Read More
Subscribe
Notify of
guest
2 Comments
Newest
Oldest Most Voted
Puja kushwaha
Puja kushwaha
30 days ago

Using the Jenkins command line can make routine tasks easier to automate, especially in scripts and build workflows. It is important to use a dedicated account with only the permissions needed for each task. Store credentials securely rather than placing passwords or tokens directly in commands. Testing authentication with a low-risk operation helps confirm access before running changes. These precautions keep command-line workflows useful without exposing the Jenkins server to avoidable risks.

Joshua Reed
Joshua Reed
1 month ago

When accessing Jenkins through the command line, teams should pay close attention to authentication methods and credential handling in automated scripts. Storing passwords or API tokens directly in shell commands can expose them through terminal history, process logs, or shared scripts. Using Jenkins API tokens with appropriate permissions, storing secrets in a secure credentials manager, and enforcing HTTPS can reduce these risks. It is also useful to handle expired tokens and failed authentication gracefully so that automation can report errors clearly without exposing sensitive information.

2
0
Would love your thoughts, please comment.x
()
x