Jenkins Cheat Sheet
Operate Jenkins — CLI, pipeline syntax, credentials, builds, and the JSON/Groovy you reach for daily.
Jenkins CLI
6java -jar jenkins-cli.jar -s http://HOST helpList CLI commands
java -jar jenkins-cli.jar -s URL build JOBTrigger a job build
java -jar jenkins-cli.jar -s URL build JOB -p PARAM=valueBuild with parameters
java -jar jenkins-cli.jar -s URL console JOB 3Console output of build 3
java -jar jenkins-cli.jar -s URL restartGraceful restart
java -jar jenkins-cli.jar -s URL create-job JOB < config.xmlCreate a job from XML
REST API
6curl -u USER:TOKEN http://HOST/api/jsonOverview JSON
curl -u USER:TOKEN http://HOST/job/JOB/api/jsonJob details and builds
curl -X POST -u USER:TOKEN http://HOST/job/JOB/buildTrigger 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/consoleTextLast build console text
curl -X POST http://HOST/scriptText -d 'script=println(build.jenkins.version)'Run Groovy via script console
Declarative Pipeline
10pipeline { 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: trueGet 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
3withCredentials([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.xmlCreate a credential via CLI
Operations
6ls $JENKINS_HOME/jobsEvery job as a config.xml
find $JENKINS_HOME -name '*.log' -size +100MFind huge log files
java -jar jenkins.war --httpPort=8080Run the controller manually
jenkins-plugin-cli --plugins kubernetes workflow-aggregatorInstall plugins in the official image
curl -u USER:TOKEN http://HOST/scriptText -d 'script=jenkins.model.Jenkins.instance.doQuietDown()'Safe quiet down
systemctl status jenkinsService status