← Back to DevOpsCommands

Jenkins

Jenkins Commands Cheat Sheet

Practical Jenkins commands for jobs, builds, pipelines, agents, plugins, credentials, logs, REST API, CI/CD and troubleshooting.

17 categories85+ commands

Jenkins Command Categories

Jump directly to the Jenkins commands you need.

Showing 85 commands across 17 categories.

Jenkins CLI and Server

5 commands
java -jar jenkins-cli.jar -s http://localhost:8080/ help

Display available Jenkins CLI commands.

java -jar jenkins-cli.jar -s http://localhost:8080/ version

Display the Jenkins CLI/server version.

java -jar jenkins-cli.jar -s http://localhost:8080/ who-am-i

Display the authenticated Jenkins user.

java -jar jenkins-cli.jar -s http://localhost:8080/ help build

Display help for the Jenkins build CLI command.

java -jar jenkins-cli.jar -s http://localhost:8080/ help console

Display help for the Jenkins console CLI command.

Jobs

6 commands
java -jar jenkins-cli.jar -s http://localhost:8080/ list-jobs

List Jenkins jobs visible to the authenticated user.

java -jar jenkins-cli.jar -s http://localhost:8080/ create-job my-job

Create a Jenkins job from XML supplied through standard input.

java -jar jenkins-cli.jar -s http://localhost:8080/ get-job my-job

Retrieve the XML configuration of a Jenkins job.

java -jar jenkins-cli.jar -s http://localhost:8080/ update-job my-job

Update an existing Jenkins job using XML configuration.

java -jar jenkins-cli.jar -s http://localhost:8080/ copy-job old-job new-job

Create a new job by copying an existing Jenkins job.

java -jar jenkins-cli.jar -s http://localhost:8080/ delete-job my-job

Delete a Jenkins job.

Builds

5 commands
java -jar jenkins-cli.jar -s http://localhost:8080/ build my-job

Trigger a Jenkins job build.

java -jar jenkins-cli.jar -s http://localhost:8080/ build my-job -s

Trigger a build and wait until the build starts.

java -jar jenkins-cli.jar -s http://localhost:8080/ build my-job -f

Trigger a build and wait until it finishes.

java -jar jenkins-cli.jar -s http://localhost:8080/ build my-job -p VERSION=1.0

Trigger a parameterized Jenkins build with a parameter value.

java -jar jenkins-cli.jar -s http://localhost:8080/ console my-job

Display the console output of a Jenkins job's latest build.

Parameterized Builds

3 commands
java -jar jenkins-cli.jar -s http://localhost:8080/ build my-job -p ENV=production

Trigger a build with a string parameter.

java -jar jenkins-cli.jar -s http://localhost:8080/ build my-job -p BRANCH=main

Trigger a build using a Git branch parameter.

java -jar jenkins-cli.jar -s http://localhost:8080/ build my-job -p IMAGE_TAG=v1.2.0

Pass an image tag to a Jenkins build.

Pipelines

7 commands
java -jar jenkins-cli.jar -s http://localhost:8080/ get-job my-pipeline

Retrieve the configuration of a Jenkins Pipeline job.

java -jar jenkins-cli.jar -s http://localhost:8080/ build my-pipeline

Trigger a Jenkins Pipeline build.

java -jar jenkins-cli.jar -s http://localhost:8080/ console my-pipeline

Display console output from the Pipeline's latest build.

pipeline { agent any }

Define a Declarative Jenkins Pipeline that can execute on any available agent.

stage('Build') { steps { sh 'npm run build' } }

Define a Pipeline stage that executes a build command.

sh 'docker build -t myapp .'

Execute a shell command from a Jenkins Pipeline on a Unix-like agent.

bat 'docker build -t myapp .'

Execute a Windows batch command from a Jenkins Pipeline.

Pipeline Environment and Parameters

5 commands
environment { APP_ENV = 'production' }

Define environment variables for a Declarative Pipeline.

parameters { string(name: 'BRANCH', defaultValue: 'main') }

Define a string parameter for a Jenkins Pipeline.

echo "${env.BUILD_NUMBER}"

Print the current Jenkins build number from a Pipeline.

echo "${params.BRANCH}"

Read a Pipeline parameter.

withCredentials([...])

Temporarily expose configured Jenkins credentials to Pipeline steps.

Agents and Nodes

4 commands
java -jar jenkins-cli.jar -s http://localhost:8080/ list-nodes

List Jenkins agents/nodes available to the authenticated user.

java -jar jenkins-cli.jar -s http://localhost:8080/ get-node node1

Display configuration information for a Jenkins node.

java -jar jenkins-cli.jar -s http://localhost:8080/ offline-node node1 -m "Maintenance"

Mark a Jenkins node offline with a maintenance message.

java -jar jenkins-cli.jar -s http://localhost:8080/ online-node node1

Bring a Jenkins node back online.

Plugins

6 commands
java -jar jenkins-cli.jar -s http://localhost:8080/ list-plugins

List installed Jenkins plugins.

java -jar jenkins-cli.jar -s http://localhost:8080/ install-plugin workflow-aggregator

Install a Jenkins plugin by its short name.

java -jar jenkins-cli.jar -s http://localhost:8080/ install-plugin git

Install the Jenkins Git plugin.

java -jar jenkins-cli.jar -s http://localhost:8080/ install-plugin docker-workflow

Install the Jenkins Docker Pipeline integration plugin.

java -jar jenkins-cli.jar -s http://localhost:8080/ restart

Restart Jenkins after plugin or configuration changes when permitted.

java -jar jenkins-cli.jar -s http://localhost:8080/ safe-restart

Restart Jenkins after running builds have completed.

Credentials

4 commands
withCredentials([usernamePassword(...)])

Use a configured username/password credential securely inside a Pipeline.

withCredentials([string(...)])

Use a configured secret text credential inside a Pipeline.

withCredentials([file(...)])

Use a configured secret file credential inside a Pipeline.

credentials('docker-registry')

Reference a Jenkins credential from a Declarative Pipeline.

Logs and Console Output

4 commands
java -jar jenkins-cli.jar -s http://localhost:8080/ console my-job

Display the latest console output for a job.

java -jar jenkins-cli.jar -s http://localhost:8080/ console my-job 25

Display console output for a specific build number.

java -jar jenkins-cli.jar -s http://localhost:8080/ console my-job -f

Follow console output while a build is running.

echo "Build ${env.BUILD_NUMBER}"

Print build information to the Jenkins Pipeline console.

REST API

5 commands
curl http://localhost:8080/api/json

Retrieve Jenkins information through the JSON REST API.

curl http://localhost:8080/job/my-job/api/json

Retrieve JSON information about a specific Jenkins job.

curl http://localhost:8080/job/my-job/lastBuild/api/json

Retrieve information about the latest build of a Jenkins job.

curl http://localhost:8080/job/my-job/lastBuild/consoleText

Retrieve plain-text console output from the latest build.

curl -X POST http://localhost:8080/job/my-job/build

Trigger a Jenkins build through the REST API when authentication and permissions allow it.

Jenkins Environment Variables

6 commands
echo $BUILD_NUMBER

Display the current Jenkins build number from a Unix-like shell.

echo $BUILD_ID

Display the current Jenkins build identifier.

echo $BUILD_URL

Display the URL of the current Jenkins build.

echo $JOB_NAME

Display the current Jenkins job name.

echo $WORKSPACE

Display the workspace directory on the Jenkins agent.

echo $GIT_COMMIT

Display the Git commit associated with the build when Git integration provides it.

Workspace and Cleanup

4 commands
deleteDir()

Delete the current Pipeline workspace contents.

cleanWs()

Clean the Jenkins workspace when the Workspace Cleanup plugin is available.

dir('frontend') { ... }

Execute Pipeline steps inside a specific workspace directory.

ws('/custom/workspace') { ... }

Execute Pipeline steps using a specified workspace location.

Jenkins Administration

6 commands
java -jar jenkins-cli.jar -s http://localhost:8080/ reload-configuration

Reload Jenkins configuration from disk.

java -jar jenkins-cli.jar -s http://localhost:8080/ reload-job my-job

Reload a job configuration from disk when applicable.

java -jar jenkins-cli.jar -s http://localhost:8080/ quiet-down

Prevent new builds from starting while Jenkins completes existing work.

java -jar jenkins-cli.jar -s http://localhost:8080/ cancel-quiet-down

Cancel quiet-down mode and allow new builds to start.

java -jar jenkins-cli.jar -s http://localhost:8080/ restart

Restart the Jenkins controller.

java -jar jenkins-cli.jar -s http://localhost:8080/ safe-restart

Restart Jenkins after running builds have completed.

Build Control

3 commands
java -jar jenkins-cli.jar -s http://localhost:8080/ stop-builds my-job

Stop builds for a job when supported by the installed Jenkins CLI command set.

java -jar jenkins-cli.jar -s http://localhost:8080/ build my-job -f

Trigger a build and wait for its completion.

java -jar jenkins-cli.jar -s http://localhost:8080/ console my-job -f

Follow live console output from the latest build.

CI/CD Workflow

6 commands
checkout scm

Check out the source code configured for the Jenkins Pipeline.

sh 'npm ci'

Install Node.js dependencies in a Unix-like Jenkins agent.

sh 'npm run build'

Build a Node.js application in a Jenkins Pipeline.

sh 'docker build -t myapp:${BUILD_NUMBER} .'

Build a Docker image using the Jenkins build number as the image tag.

sh 'docker push registry.example.com/myapp:${BUILD_NUMBER}'

Push a built Docker image to a container registry.

sh 'kubectl apply -f k8s/'

Deploy Kubernetes manifests from a Jenkins Pipeline when kubectl is configured on the agent.

Jenkins Troubleshooting

6 commands
java -jar jenkins-cli.jar -s http://localhost:8080/ version

Verify Jenkins server and CLI version information.

java -jar jenkins-cli.jar -s http://localhost:8080/ who-am-i

Verify the authenticated Jenkins identity and permissions.

java -jar jenkins-cli.jar -s http://localhost:8080/ list-jobs

Check whether the expected jobs are accessible.

java -jar jenkins-cli.jar -s http://localhost:8080/ list-nodes

Check available Jenkins agents when builds cannot start.

java -jar jenkins-cli.jar -s http://localhost:8080/ list-plugins

Inspect installed plugins when Pipeline features are unavailable.

java -jar jenkins-cli.jar -s http://localhost:8080/ console my-job -f

Follow live build logs while troubleshooting a failed or hanging build.

Recommended Jenkins Workflow

# Check out source
checkout scm

# Install dependencies
sh 'npm ci'

# Run tests
sh 'npm test'

# Build application
sh 'npm run build'

# Build container
sh 'docker build -t myapp:$BUILD_NUMBER .'

# Push container
sh 'docker push registry.example.com/myapp:$BUILD_NUMBER'

# Deploy
sh 'kubectl apply -f k8s/'

DevOpsCommands Tip

Keep Jenkins pipelines in source control with a Jenkinsfile. Store secrets in Jenkins Credentials rather than directly inside Pipeline code, and make build stages small and easy to troubleshoot.