0
0
Jenkinsdevops~20 mins

Declarative pipeline syntax in Jenkins - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Declarative Pipeline Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Output of a simple Declarative Pipeline
What will be the output of the following Jenkins Declarative Pipeline when run?
Jenkins
pipeline {
  agent any
  stages {
    stage('Example') {
      steps {
        echo 'Hello, Jenkins!'
      }
    }
  }
}
AConsole shows: Hello, Jenkins!
BBuild fails with syntax error
CPipeline runs but no output is shown
DBuild is skipped automatically
Attempts:
2 left
💡 Hint
Look at the echo step inside the stage.
Configuration
intermediate
2:00remaining
Correct agent declaration in Declarative Pipeline
Which option correctly declares an agent that runs on any available node in a Jenkins Declarative Pipeline?
Aagent any
Bagent none
Cagent label 'any'
Dagent node
Attempts:
2 left
💡 Hint
The keyword for any available node is a simple word.
🔀 Workflow
advanced
2:00remaining
Stage execution order in Declarative Pipeline
Given this Declarative Pipeline, in what order will the stages execute?
Jenkins
pipeline {
  agent any
  stages {
    stage('Build') {
      steps { echo 'Building...' }
    }
    stage('Test') {
      steps { echo 'Testing...' }
    }
    stage('Deploy') {
      steps { echo 'Deploying...' }
    }
  }
}
ABuild, Deploy, Test
BDeploy, Test, Build
CTest, Build, Deploy
DBuild, Test, Deploy
Attempts:
2 left
💡 Hint
Stages run in the order they are defined.
Troubleshoot
advanced
2:00remaining
Error caused by missing steps block
What error will Jenkins show if a stage in a Declarative Pipeline is missing the required steps block?
Jenkins
pipeline {
  agent any
  stages {
    stage('Build') {
      echo 'Building...'
    }
  }
}
ANo error, pipeline runs fine
BRuntime error: 'echo' command not found
CSyntax error: Expected a steps block inside stage
DWarning: Missing steps block, but pipeline continues
Attempts:
2 left
💡 Hint
Declarative Pipeline requires steps inside stages.
Best Practice
expert
2:00remaining
Proper use of post section in Declarative Pipeline
Which option correctly uses the post section to always run a cleanup step after all stages, regardless of build result?
A
post {
  success {
    echo 'Cleaning up...'
  }
}
B
post {
  always {
    echo 'Cleaning up...'
  }
}
C
post {
  failure {
    echo 'Cleaning up...'
  }
}
D
post {
  changed {
    echo 'Cleaning up...'
  }
}
Attempts:
2 left
💡 Hint
You want the cleanup to run no matter what happens.