Jenkins Cheat Sheet

Operate Jenkins — CLI, pipeline syntax, credentials, builds, and the JSON/Groovy you reach for daily.

CI/CD5 sections · 31 commands
⌘K

Jenkins CLI

6
java -jar jenkins-cli.jar -s http://HOST help

List CLI commands

java -jar jenkins-cli.jar -s URL build JOB

Trigger a job build

java -jar jenkins-cli.jar -s URL build JOB -p PARAM=value

Build with parameters

java -jar jenkins-cli.jar -s URL console JOB 3

Console output of build 3

java -jar jenkins-cli.jar -s URL restart

Graceful restart

java -jar jenkins-cli.jar -s URL create-job JOB < config.xml

Create a job from XML

REST API

6
curl -u USER:TOKEN http://HOST/api/json

Overview JSON

curl -u USER:TOKEN http://HOST/job/JOB/api/json

Job details and builds

curl -X POST -u USER:TOKEN http://HOST/job/JOB/build

Trigger a build (CSRF may need crumbs)

curl -X POST -u USER:TOKEN 'http://HOST/job/JOB/buildWithParameters?PARAM=value'

Parameterized build

curl -u USER:TOKEN http://HOST/job/JOB/lastBuild/consoleText

Last build console text

curl -X POST http://HOST/scriptText -d 'script=println(build.jenkins.version)'

Run Groovy via script console

Declarative Pipeline

10
pipeline { options { timeout(time: 15, unit: 'MINUTES') } }

Timeout the whole run

pipeline { options { buildDiscarder(logRotator(numToKeepStr: '10')) } }

Keep 10 builds

steps { echo 'hello' }

Run a step

stage('Build') { steps { sh 'make build' } }

Named stage

agent { docker { image 'node:20', args '-u root' } }

Run inside a container

post { always { archiveArtifacts ... } }

Post-build cleanup

sh script: 'cmd', returnStatus: true

Get exit status without failing

withEnv(['VAR=value']) { ... }

Scoped environment

parallel a: {...}, b: {...}

Run stages in parallel

credentials(identifier) { ... }

Bind a credential to env vars

Credentials & Secrets

3
withCredentials([usernamePassword(credentialsId: 'x', usernameVariable: 'U', passwordVariable: 'P')]) { sh 'deploy $U $P' }

Use a credential in a build

withCredentials([[clazz: 'StringBinding', credentialsId: 'token', variable: 'TOK']]) { ... }

Secret text binding

java -jar jenkins-cli.jar -s URL create-credentials-by-xml system::system::jenkins < cred.xml

Create a credential via CLI

Operations

6
ls $JENKINS_HOME/jobs

Every job as a config.xml

find $JENKINS_HOME -name '*.log' -size +100M

Find huge log files

java -jar jenkins.war --httpPort=8080

Run the controller manually

jenkins-plugin-cli --plugins kubernetes workflow-aggregator

Install plugins in the official image

curl -u USER:TOKEN http://HOST/scriptText -d 'script=jenkins.model.Jenkins.instance.doQuietDown()'

Safe quiet down

systemctl status jenkins

Service status