Bird
Raised Fist0
Jenkinsdevops~20 mins

Keeping pipelines fast in Jenkins - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Pipeline Speed Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Why use parallel stages in Jenkins pipelines?

In Jenkins pipelines, what is the main benefit of using parallel stages?

AThey automatically retry failed tasks without manual intervention.
BThey save pipeline logs to external storage for auditing.
CThey ensure tasks run one after another to avoid conflicts.
DThey allow multiple tasks to run at the same time, reducing total pipeline duration.
Attempts:
2 left
💡 Hint

Think about how running tasks simultaneously affects total time.

💻 Command Output
intermediate
2:00remaining
Output of Jenkins pipeline with caching

Given this Jenkins pipeline snippet, what will be the output of the sh step on the second run?

Jenkins
pipeline {
  agent any
  stages {
    stage('Cache Example') {
      steps {
        cache(path: 'node_modules', key: 'npm-cache') {
          sh 'npm install'
        }
        sh 'ls node_modules'
      }
    }
  }
}
AFails because cache step is not a valid Jenkins pipeline step.
BLists the contents of node_modules folder quickly because dependencies are cached.
CRuns npm install every time without caching, so node_modules is empty initially.
DThrows syntax error due to missing curly braces.
Attempts:
2 left
💡 Hint

Check if cache is a built-in Jenkins pipeline step.

🔀 Workflow
advanced
2:00remaining
Optimizing Jenkins pipeline with agent allocation

You want to speed up your Jenkins pipeline by running tests simultaneously. Which pipeline snippet correctly achieves this?

A
stage('Tests') {
  steps {
    sh 'run-tests.sh'
    sh 'run-tests.sh'
  }
}
B
parallel {
  stage('Test1') {
    agent { label 'linux' }
    steps { sh 'run-tests.sh' }
  }
  stage('Test2') {
    agent { label 'windows' }
    steps { sh 'run-tests.sh' }
  }
}
C
stage('Tests') {
  agent any
  steps {
    parallel(
      test1: { sh 'run-tests.sh' },
      test2: { sh 'run-tests.sh' }
    )
  }
}
D
parallel(
  { stage('Test1') { steps { sh 'run-tests.sh' } } },
  { stage('Test2') { steps { sh 'run-tests.sh' } } }
)
Attempts:
2 left
💡 Hint

Look for the correct syntax to run parallel tasks inside a stage.

❓ Troubleshoot
advanced
2:00remaining
Why does Jenkins pipeline run slowly despite parallel stages?

A Jenkins pipeline uses parallel stages, but the total runtime is still very long. What is the most likely cause?

AThe pipeline script has syntax errors preventing parallel execution.
BThe parallel stages share the same agent, causing them to run sequentially.
CThe Jenkins master is offline, so stages cannot run.
DThe pipeline uses too many agents, causing network congestion.
Attempts:
2 left
💡 Hint

Consider how agent allocation affects parallel execution.

✅ Best Practice
expert
3:00remaining
Best practice for caching dependencies in Jenkins pipelines

What is the best practice to cache dependencies like node_modules in Jenkins pipelines to keep builds fast and reliable?

AUse a dedicated caching plugin or external cache server and restore cache before build steps.
BManually copy <code>node_modules</code> folder between builds using shell commands.
CRun <code>npm install</code> every time without caching to avoid stale dependencies.
DStore <code>node_modules</code> inside the workspace without any caching mechanism.
Attempts:
2 left
💡 Hint

Think about automated, reliable ways to reuse dependencies across builds.

Practice

(1/5)
1. Why is it important to keep Jenkins pipelines fast?
easy
A. To make the pipeline logs longer
B. To deliver code quickly and improve team efficiency
C. To increase the number of pipeline steps
D. To use more server resources

Solution

  1. Step 1: Understand pipeline speed impact

    Fast pipelines reduce wait time for developers and speed up delivery.
  2. Step 2: Identify the benefit of fast pipelines

    Faster pipelines improve team efficiency and allow quicker feedback.
  3. Final Answer:

    To deliver code quickly and improve team efficiency -> Option B
  4. Quick Check:

    Fast pipelines = faster delivery [OK]
Hint: Fast pipelines help teams deliver code quickly [OK]
Common Mistakes:
  • Thinking more steps make pipelines faster
  • Believing longer logs improve speed
  • Assuming more resource use equals speed
2. Which Jenkins pipeline syntax correctly sets a timeout of 10 minutes for a stage?
easy
A. timeout(time: 10, unit: 'MINUTES') { /* steps */ }
B. timeout(10 minutes) { /* steps */ }
C. timeout(10) { /* steps */ }
D. timeout(time=10, unit='minutes') { /* steps */ }

Solution

  1. Step 1: Recall Jenkins timeout syntax

    The correct syntax uses named parameters: time and unit.
  2. Step 2: Match correct syntax

    timeout(time: 10, unit: 'MINUTES') { /* steps */ } uses timeout(time: 10, unit: 'MINUTES') which is valid Groovy syntax.
  3. Final Answer:

    timeout(time: 10, unit: 'MINUTES') { /* steps */ } -> Option A
  4. Quick Check:

    timeout(time: 10, unit: 'MINUTES') = correct syntax [OK]
Hint: Use named parameters time and unit for timeout [OK]
Common Mistakes:
  • Using timeout(10 minutes) without quotes
  • Missing unit parameter
  • Using equal signs instead of colons
3. What will be the output of this Jenkins pipeline snippet?
pipeline {
  agent any
  stages {
    stage('Parallel') {
      parallel {
        stage('A') { steps { echo 'Running A' } }
        stage('B') { steps { echo 'Running B' } }
      }
    }
  }
}
medium
A. Runs stages A and B at the same time
B. Runs stages A and B one after another
C. Runs only stage A
D. Pipeline fails due to syntax error

Solution

  1. Step 1: Analyze parallel block syntax in Jenkins Declarative Pipeline

    The parallel block can contain nested stages inside it in Declarative Pipeline syntax.
  2. Step 2: Identify the behavior

    Stages A and B inside parallel run concurrently, so both run at the same time.
  3. Final Answer:

    Runs stages A and B at the same time -> Option A
  4. Quick Check:

    parallel runs stages concurrently [OK]
Hint: parallel block runs nested stages concurrently [OK]
Common Mistakes:
  • Thinking stages can not be nested inside parallel
  • Assuming parallel runs stages sequentially
  • Believing the syntax is invalid
4. You have a Jenkins pipeline that runs slowly. Which change will help fix this issue?
stage('Build') {
  steps {
    sh 'sleep 60'
  }
}
medium
A. Add more sleep commands to wait longer
B. Increase the timeout to 120 minutes
C. Change sleep to a non-blocking command
D. Remove the sleep command or reduce its duration

Solution

  1. Step 1: Identify slow step

    The 'sleep 60' command pauses the pipeline for 60 seconds, slowing it down.
  2. Step 2: Fix by removing or reducing sleep

    Removing or reducing sleep will speed up the pipeline.
  3. Final Answer:

    Remove the sleep command or reduce its duration -> Option D
  4. Quick Check:

    Removing delays = faster pipeline [OK]
Hint: Remove unnecessary waits like sleep to speed up pipelines [OK]
Common Mistakes:
  • Adding more sleep commands
  • Increasing timeout instead of fixing delay
  • Thinking sleep is non-blocking
5. You want to speed up a Jenkins pipeline by skipping tests when a commit message contains '[skip tests]'. Which pipeline step correctly implements this logic?
hard
A. if (env.GIT_COMMIT_MESSAGE.contains('[skip tests]')) { sh 'run-tests.sh' } else { echo 'Skipping tests' }
B. if (env.GIT_COMMIT_MESSAGE == '[skip tests]') { sh 'run-tests.sh' } else { echo 'Skipping tests' }
C. if (env.GIT_COMMIT_MESSAGE.contains('[skip tests]')) { echo 'Skipping tests'; } else { sh 'run-tests.sh' }
D. if (env.GIT_COMMIT_MESSAGE.contains('skip tests')) { sh 'run-tests.sh' } else { echo 'Skipping tests' }

Solution

  1. Step 1: Understand the condition to skip tests

    Tests should be skipped if commit message contains '[skip tests]'.
  2. Step 2: Match correct logic and commands

    if (env.GIT_COMMIT_MESSAGE.contains('[skip tests]')) { echo 'Skipping tests'; } else { sh 'run-tests.sh' } checks for '[skip tests]' and skips tests by echoing message; else runs tests.
  3. Final Answer:

    if (env.GIT_COMMIT_MESSAGE.contains('[skip tests]')) { echo 'Skipping tests'; } else { sh 'run-tests.sh' } -> Option C
  4. Quick Check:

    Correct condition and action = if (env.GIT_COMMIT_MESSAGE.contains('[skip tests]')) { echo 'Skipping tests'; } else { sh 'run-tests.sh' } [OK]
Hint: Use contains('[skip tests]') to conditionally skip tests [OK]
Common Mistakes:
  • Using equality instead of contains
  • Reversing the if-else logic
  • Missing brackets in string match
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard