Interview Prep/Real-World Interview/Write-a-pipeline tasks

Write a Jenkinsfile that runs stages in parallel.

IntermediateHands-onWrite-a-pipeline tasks
Answer
pipeline {
  agent none
  stages {
    stage('Checks') {
      parallel {
        stage('Unit')  { agent { docker { image 'node:22' } } steps { sh 'npm ci && npm test' } }
        stage('Lint')  { agent { docker { image 'node:22' } } steps { sh 'npm ci && npm run lint' } }
        stage('Trivy fs') {
          agent {
            docker {
              image 'aquasec/trivy:0.56.2'
              args '--entrypoint='
            }
          }
          steps { sh 'trivy fs --exit-code 1 --severity CRITICAL .' }
        }
      }
    }
  }
}

Key trick → agent none at the top with an agent per parallel stage gives each branch its own executor. Add failFast true to abort siblings when one fails.

All Real-World Interview questions Roadmap: Interview readiness

More on Write-a-pipeline tasks