0
0
Jenkinsdevops~20 mins

Pipeline stages and steps in Jenkins - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Pipeline Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Output of a simple Jenkins pipeline with stages
What will be the output in the Jenkins console log after running this pipeline?
Jenkins
pipeline {
  agent any
  stages {
    stage('Build') {
      steps {
        echo 'Building project'
      }
    }
    stage('Test') {
      steps {
        echo 'Running tests'
      }
    }
  }
}
A[Pipeline] stage\n[Pipeline] { (Test)\n[Pipeline] echo\nRunning tests\n[Pipeline] }\n[Pipeline] stage\n[Pipeline] { (Build)\n[Pipeline] echo\nBuilding project\n[Pipeline] }
B[Pipeline] stage\n[Pipeline] { (Build)\n[Pipeline] echo\nBuilding project\n[Pipeline] }\n[Pipeline] stage\n[Pipeline] { (Test)\n[Pipeline] echo\nRunning tests\n[Pipeline] }
C[Pipeline] stage\n[Pipeline] { (Build)\n[Pipeline] echo\nRunning tests\n[Pipeline] }\n[Pipeline] stage\n[Pipeline] { (Test)\n[Pipeline] echo\nBuilding project\n[Pipeline] }
D[Pipeline] stage\n[Pipeline] { (Build)\n[Pipeline] echo\nBuilding project\n[Pipeline] }\n[Pipeline] stage\n[Pipeline] { (Test)\n[Pipeline] echo\nBuilding project\n[Pipeline] }
Attempts:
2 left
💡 Hint
Stages run in the order they are defined.
🧠 Conceptual
intermediate
1:30remaining
Understanding parallel stages in Jenkins pipeline
Which statement about parallel stages in Jenkins pipeline is true?
AParallel stages run one after another in sequence.
BParallel stages cannot contain steps.
CParallel stages must be defined outside the stages block.
DParallel stages run simultaneously, allowing multiple tasks at the same time.
Attempts:
2 left
💡 Hint
Think about how parallel means 'at the same time'.
Configuration
advanced
2:30remaining
Correct syntax for a Jenkins pipeline with parallel stages
Which pipeline code correctly defines two parallel stages named 'Test1' and 'Test2' that echo different messages?
A
pipeline {
  agent any
  stages {
    stage('ParallelTests') {
      parallel {
        stage('Test1') {
          steps { echo 'Running Test1' }
        }
        stage('Test2') {
          steps { echo 'Running Test2' }
        }
      }
    }
  }
}
B
pipeline {
  agent any
  stages {
    parallel {
      stage('Test1') {
        steps { echo 'Running Test1' }
      }
      stage('Test2') {
        steps { echo 'Running Test2' }
      }
    }
  }
}
C
pipeline {
  agent any
  stages {
    stage('Test1') {
      parallel {
        steps { echo 'Running Test1' }
      }
    }
    stage('Test2') {
      steps { echo 'Running Test2' }
    }
  }
}
D
pipeline {
  agent any
  stages {
    stage('ParallelTests') {
      steps {
        parallel {
          Test1: { echo 'Running Test1' },
          Test2: { echo 'Running Test2' }
        }
      }
    }
  }
}
Attempts:
2 left
💡 Hint
Parallel block must be inside a stage, and parallel stages are nested inside it.
Troubleshoot
advanced
2:00remaining
Identifying error in Jenkins pipeline stage definition
What error will this Jenkins pipeline produce?
Jenkins
pipeline {
  agent any
  stages {
    stage('Build')
      steps {
        echo 'Building'
      }
    }
  }
}
ASyntaxError: Expected a block after stage declaration
BRuntimeError: Missing agent declaration
CNo error, pipeline runs successfully
DTypeError: steps block misplaced
Attempts:
2 left
💡 Hint
Check the braces and indentation after the stage keyword.
🔀 Workflow
expert
3:00remaining
Order of execution in a Jenkins pipeline with nested stages
Given this pipeline, what is the order of echo outputs in the console log?
Jenkins
pipeline {
  agent any
  stages {
    stage('Deploy') {
      stages {
        stage('Deploy to Dev') {
          steps { echo 'Deploying to Dev' }
        }
        stage('Deploy to Prod') {
          steps { echo 'Deploying to Prod' }
        }
      }
    }
    stage('Cleanup') {
      steps { echo 'Cleaning up' }
    }
  }
}
ACleaning up\nDeploying to Dev\nDeploying to Prod
BDeploying to Dev\nCleaning up\nDeploying to Prod
CDeploying to Dev\nDeploying to Prod\nCleaning up
DDeploying to Prod\nDeploying to Dev\nCleaning up
Attempts:
2 left
💡 Hint
Nested stages run in order inside their parent stage before moving on.