Skip to content

Jenkins Cheatsheet

Automation server for building, testing, and deploying software.

01

Pipeline

Declarative

Declarative pipeline in Groovy DSL.

jenkins
pipeline {
  agent any
  stages {
    stage("Build") {
      steps { sh "npm run build" }
    }
    stage("Test") {
      steps { sh "npm test" }
    }
    stage("Deploy") {
      steps { sh "deploy.sh" }
    }
  }
}

Environment

Environment variables and credentials.

jenkins
pipeline {
  environment {
    NODE_ENV = "production"
    API_KEY = credentials("api-key")
  }
}
02

Features

When

Conditional stage execution.

jenkins
stage("Deploy") {
  when { branch "main" }
  steps { sh "deploy.sh" }
}

Post

Post-build actions.

jenkins
post {
  success { echo "Build passed" }
  failure { emailext to: "[email protected]", subject: "Build failed" }
  always { archiveArtifacts "dist/**" }
}

Parallel

Parallel stage execution.

jenkins
stages {
  stage("Test") {
    parallel {
      stage("Unit") { steps { sh "npm run test:unit" } }
      stage("E2E") { steps { sh "npm run test:e2e" } }
    }
  }
}

Was this helpful?