0
0
Jenkinsdevops~5 mins

Pipeline visualization and debugging in Jenkins - Commands & Configuration

Choose your learning style9 modes available
Introduction
When you run automated tasks in Jenkins, you want to see what is happening step-by-step. Pipeline visualization helps you watch the progress and find problems quickly. Debugging means fixing errors by checking logs and stages.
When you want to see which step of your build or deployment is running or failed
When you need to find why a Jenkins pipeline did not complete successfully
When you want to understand the flow of your automated tasks visually
When you want to add pauses or checks to your pipeline to test parts separately
When you want to improve your pipeline by seeing detailed logs and stage results
Config File - Jenkinsfile
Jenkinsfile
pipeline {
  agent any
  stages {
    stage('Build') {
      steps {
        echo 'Building the project'
      }
    }
    stage('Test') {
      steps {
        echo 'Running tests'
      }
    }
    stage('Deploy') {
      steps {
        echo 'Deploying application'
      }
    }
  }
  post {
    failure {
      echo 'Pipeline failed. Check logs for details.'
    }
  }
}

This Jenkinsfile defines a simple pipeline with three stages: Build, Test, and Deploy.

Each stage prints a message to show progress.

The post section runs after the pipeline and prints a message if the pipeline fails.

This setup helps visualize each step and debug by checking stage outputs and failure messages.

Commands
This command starts the Jenkins pipeline named 'my-pipeline' and waits for it to finish. It shows the progress in the terminal so you can watch the pipeline running live.
Terminal
jenkins-cli build my-pipeline -s
Expected OutputExpected
Started build #1 [Pipeline] Start of Pipeline [Pipeline] echo Building the project [Pipeline] echo Running tests [Pipeline] echo Deploying application [Pipeline] End of Pipeline Finished: SUCCESS
-s - Waits for the build to complete and shows live output
This command fetches the full console output of build number 1 of 'my-pipeline'. It helps you see all logs and messages to find errors or understand what happened during the run.
Terminal
jenkins-cli console my-pipeline 1
Expected OutputExpected
[Pipeline] Start of Pipeline [Pipeline] echo Building the project [Pipeline] echo Running tests [Pipeline] echo Deploying application [Pipeline] End of Pipeline Finished: SUCCESS
This command lists all Jenkins jobs (pipelines) available. It helps you confirm the pipeline name before running or debugging it.
Terminal
jenkins-cli list-jobs
Expected OutputExpected
my-pipeline example-job build-and-test
This command re-runs build number 1 of 'my-pipeline'. It is useful for debugging by repeating the exact same pipeline run to check if the problem happens again.
Terminal
jenkins-cli replay my-pipeline 1
Expected OutputExpected
Replaying build #1 of job my-pipeline Started build #2 [Pipeline] Start of Pipeline [Pipeline] echo Building the project [Pipeline] echo Running tests [Pipeline] echo Deploying application [Pipeline] End of Pipeline Finished: SUCCESS
Key Concept

If you remember nothing else from this pattern, remember: watching your pipeline run step-by-step and checking logs helps you find and fix problems fast.

Common Mistakes
Trying to debug without checking the console output
You miss important error messages and details that explain why the pipeline failed
Always fetch and read the console output after a failed run to understand the problem
Running a pipeline without knowing the exact job name
The command fails because Jenkins cannot find the job
Use 'jenkins-cli list-jobs' to confirm the job name before running commands
Not waiting for the pipeline to finish when starting it
You cannot see the full output or know if it succeeded or failed immediately
Use the '-s' flag with 'jenkins-cli build' to wait and see live output
Summary
Use a Jenkinsfile to define pipeline stages that show progress and help debugging.
Run the pipeline with 'jenkins-cli build -s' to watch it live and confirm success.
Check full logs with 'jenkins-cli console' to find errors and understand pipeline behavior.