0
0
Jenkinsdevops~5 mins

Keeping pipelines fast in Jenkins - Commands & Configuration

Choose your learning style9 modes available
Introduction
Long-running pipelines slow down development and waste resources. Keeping pipelines fast helps deliver changes quickly and keeps your team productive.
When your build takes too long and blocks other work
When you want to get quick feedback on code changes
When you want to save cloud or server costs by reducing pipeline runtime
When you want to run multiple tests in parallel to speed up validation
When you want to avoid unnecessary steps for small changes
Config File - Jenkinsfile
Jenkinsfile
pipeline {
  agent any
  options {
    timeout(time: 10, unit: 'MINUTES')
    skipStagesAfterUnstable()
  }
  stages {
    stage('Checkout') {
      steps {
        checkout scm
      }
    }
    stage('Build') {
      steps {
        sh 'make build'
      }
    }
    stage('Test') {
      parallel {
        stage('Unit Tests') {
          steps {
            sh 'make test-unit'
          }
        }
        stage('Integration Tests') {
          steps {
            sh 'make test-integration'
          }
        }
      }
    }
    stage('Deploy') {
      when {
        branch 'main'
      }
      steps {
        sh 'make deploy'
      }
    }
  }
}

This Jenkinsfile defines a pipeline with these speed-focused features:

  • timeout: Stops the pipeline if it runs longer than 10 minutes to avoid wasting time.
  • skipStagesAfterUnstable: Skips later stages if an earlier stage fails or is unstable, saving time.
  • parallel: Runs unit and integration tests at the same time to reduce total test time.
  • when branch 'main': Runs deployment only on the main branch to avoid unnecessary deploys on feature branches.
Commands
This command updates the Jenkins pipeline configuration with the new Jenkinsfile that includes speed optimizations.
Terminal
jenkins-jobs --conf jenkins.ini update my-pipeline
Expected OutputExpected
Job updated successfully: my-pipeline
Starts the pipeline build and waits for it to finish, so you can see the results immediately.
Terminal
jenkins-cli build my-pipeline -s
Expected OutputExpected
[Pipeline] Start of Pipeline [Pipeline] stage: Checkout [Pipeline] Checkout scm [Pipeline] stage: Build [Pipeline] sh [Pipeline] stage: Test [Pipeline] parallel [Pipeline] stage: Unit Tests [Pipeline] sh [Pipeline] stage: Integration Tests [Pipeline] sh [Pipeline] stage: Deploy [Pipeline] sh [Pipeline] End of Pipeline Finished: SUCCESS
-s - Waits for the build to complete before returning output
Shows the console output of the last pipeline run to verify stages ran quickly and in parallel.
Terminal
jenkins-cli console my-pipeline
Expected OutputExpected
[Pipeline] Start of Pipeline [Pipeline] stage: Checkout [Pipeline] Checkout scm [Pipeline] stage: Build [Pipeline] sh [Pipeline] stage: Test [Pipeline] parallel [Pipeline] stage: Unit Tests [Pipeline] sh [Pipeline] stage: Integration Tests [Pipeline] sh [Pipeline] stage: Deploy [Pipeline] sh [Pipeline] End of Pipeline Finished: SUCCESS
Key Concept

If you remember nothing else from this pattern, remember: run tests in parallel and skip unnecessary steps to keep pipelines fast.

Common Mistakes
Running all tests sequentially without parallel stages
This makes the pipeline take longer than needed because tests wait for each other.
Use Jenkins 'parallel' to run independent tests at the same time.
Not setting timeouts on pipeline stages
A stuck or slow stage can block the entire pipeline and waste resources.
Use the 'timeout' option to stop stages that run too long.
Deploying on every branch instead of only main or release branches
Deploying unnecessary builds wastes time and can cause confusion.
Use 'when' conditions to deploy only on specific branches.
Summary
Use 'parallel' stages to run tests or tasks at the same time and reduce total pipeline time.
Set timeouts to stop slow or stuck stages and save resources.
Use conditions to skip deployment or other steps on branches where they are not needed.