Safeguard
Security Guides•

Should Jenkins scripts use API tokens or passwords?

Use Jenkins API tokens for scripts, not passwords. Tokens skip the crumb dance, can be loaded from files, and are easier to scope and rotate.

Safeguard Security Team
3 min read

Scripts that call Jenkins should use API tokens, not passwords. A token request skips the CSRF crumb step, can be loaded from a file instead of typed on a command line, and can be replaced without changing the account password people use to log in.

Passwords versus tokens

PointPasswordAPI token
CSRFClient must fetch a crumb from /crumbIssuer/api, keep the session cookie, and send everything on each callRequests are exempt from CSRF checks
CLIWorks with -auth but discouragedRecommended, loaded from a file
ExposureThe same secret opens the UISeparate from the login password
RotationChanges the user's loginReplace the token only

These points come from the Jenkins CSRF and CLI documentation. The CLI page says tokens taken from the user's configure page and loaded from a file with @ are the recommended way. Setting JENKINS_USER_ID and JENKINS_API_TOKEN together is another route, and -auth overrides them.

Safe habits

  1. Dedicated users. Create one automation user per integration, with the smallest permission set that works. Check it with the who-am-i CLI command.
  2. Store tokens as secrets. In other systems, use their secret store. In Jenkins, use credentials rather than writing tokens into a Jenkinsfile.
  3. Keep tokens out of command lines and logs. Loading from a file keeps them out of process listings and shell history.
  4. Rotate on a schedule and on departure. Tokens belong to a user. When people leave, check what they created.
  5. Review. Look at users with tokens and ask whether each is still needed.

What a token does not fix

A token carries the permissions of its user. If the user is an admin, a leaked token is an admin token. Scope the user, not just the credential. Also, an old plugin or core version can have its own flaws, so keep both current.

Scripts that need the older path

If you must use a username and password, follow the documented flow: request a crumb, store the session cookie from the response, then send username, password, crumb and cookie on every request. Many legacy scripts skip the crumb and break after protection is turned on, which is one reason teams disable CSRF. Switching them to tokens is the cleaner repair.

Try it yourself

The demo walks through an API security scan, which checks how endpoints handle authentication.

Click through it at your own pace, or open it full screen.

Where Safeguard fits

Safeguard scans dependencies and applies policies and gates to pipelines. Run the free scan on a repository to see sample output.

Quick check

Do API token calls need a crumb?

No. Requests using a username and API token are exempt from CSRF checks.

Where do I get a token?

From the user's configure page in Jenkins, which the CLI documentation points to.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.