0
0
Jenkinsdevops~10 mins

Keeping pipelines fast in Jenkins - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to run a stage only when changes are detected in the 'src/' directory.

Jenkins
stage('Build') {
  when {
    changeset '[1]'
  }
  steps {
    echo 'Building project...'
  }
}
Drag options to blanks, or click blank then click option'
Aexpression true
Bbranch 'main'
Cenvironment 'PROD'
D'src/**'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'branch' instead of 'changeset' for file changes.
Not specifying the path pattern correctly.
2fill in blank
medium

Complete the code to cache dependencies in a Jenkins pipeline using the 'stash' step.

Jenkins
stage('Cache Dependencies') {
  steps {
    [1] name: 'deps', includes: 'node_modules/**'
  }
}
Drag options to blanks, or click blank then click option'
Astash
BarchiveArtifacts
Cunstash
Dcheckout
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'unstash' instead of 'stash' to save files.
Using 'archiveArtifacts' which is for storing build outputs.
3fill in blank
hard

Fix the error in the pipeline code to parallelize tests correctly.

Jenkins
parallel {
  unit: {
    steps {
      sh 'run-unit-tests.sh'
    }
  },
  integration: {
    steps {
      [1] 'run-integration-tests.sh'
    }
  }
}
Drag options to blanks, or click blank then click option'
Ascript
Bsh
Cbat
Dstage
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'bat' which is for Windows batch scripts.
Using 'stage' inside parallel incorrectly.
4fill in blank
hard

Fill both blanks to enable polling for changes and ensure the source code is checked out.

Jenkins
pipeline {
  agent any
  triggers {
    pollSCM('[1]')
  }
  options {
    skipDefaultCheckout [2]
  }
  stages {
    stage('Build') {
      steps {
        echo 'Building...'
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
AH/5 * * * *
Bfalse
Dtrue
Attempts:
3 left
💡 Hint
Common Mistakes
Disabling polling causes pipeline not to trigger on changes.
Skipping checkout causes build failures.
5fill in blank
hard

Fill all three blanks to define a fast pipeline that runs tests in parallel and uses caching.

Jenkins
pipeline {
  agent any
  stages {
    stage('Prepare') {
      steps {
        [1] name: 'cache', includes: 'dependencies/**'
      }
    }
    stage('Test') {
      parallel {
        unit: {
          steps {
            [2] 'run-unit-tests.sh'
          }
        },
        integration: {
          steps {
            [3] 'run-integration-tests.sh'
          }
        }
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
Astash
Bsh
Dcheckout
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'checkout' instead of 'stash' for caching.
Using 'bat' instead of 'sh' on Linux agents.