0
0
Jenkinsdevops~20 mins

Stage block structure in Jenkins - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Stage Block Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
1:30remaining
What is the output of this Jenkins pipeline stage?

Consider this Jenkins pipeline snippet:

pipeline {
  agent any
  stages {
    stage('Build') {
      steps {
        echo 'Building project'
      }
    }
  }
}

What will Jenkins print during the 'Build' stage execution?

Jenkins
pipeline {
  agent any
  stages {
    stage('Build') {
      steps {
        echo 'Building project'
      }
    }
  }
}
A
pipeline {
  agent any
  stages {
    stage('Build') {
      steps {
        echo 'Building project'
      }
    }
  }
}
BBuild
CBuilding project
DError: Missing agent declaration
Attempts:
2 left
💡 Hint

Look at the echo command inside the steps block.

Configuration
intermediate
2:00remaining
Identify the correct stage block structure for parallel execution

Which Jenkins pipeline snippet correctly defines two parallel stages named 'Test1' and 'Test2' inside a 'Test' stage?

A
stage('Test') {
  parallel {
    stage('Test1') {
      steps { echo 'Running Test1' }
    }
    stage('Test2') {
      steps { echo 'Running Test2' }
    }
  }
}
B
stage('Test') {
  stages {
    parallel {
      stage('Test1') {
        steps { echo 'Running Test1' }
      }
      stage('Test2') {
        steps { echo 'Running Test2' }
      }
    }
  }
}
C
stage('Test') {
  steps {
    parallel {
      stage('Test1') {
        steps { echo 'Running Test1' }
      }
      stage('Test2') {
        steps { echo 'Running Test2' }
      }
    }
  }
}
D
stage('Test') {
  parallel {
    steps {
      stage('Test1') {
        echo 'Running Test1'
      }
      stage('Test2') {
        echo 'Running Test2'
      }
    }
  }
}
Attempts:
2 left
💡 Hint

Parallel stages are defined inside a parallel block directly under a stage.

Troubleshoot
advanced
2:30remaining
Why does this Jenkins pipeline fail to run stages sequentially?

Given this Jenkins pipeline snippet:

pipeline {
  agent any
  stages {
    stage('Build') {
      steps {
        echo 'Building'
      }
    }
    parallel {
      stage('Test1') {
        steps {
          echo 'Testing 1'
        }
      }
      stage('Test2') {
        steps {
          echo 'Testing 2'
        }
      }
    }
  }
}

Why does Jenkins report a syntax error?

Jenkins
pipeline {
  agent any
  stages {
    stage('Build') {
      steps {
        echo 'Building'
      }
    }
    parallel {
      stage('Test1') {
        steps {
          echo 'Testing 1'
        }
      }
      stage('Test2') {
        steps {
          echo 'Testing 2'
        }
      }
    }
  }
}
ABecause 'agent' is missing inside 'parallel'
BBecause 'steps' block is missing inside 'parallel'
CBecause 'stage' blocks cannot be nested inside 'stages'
DBecause 'parallel' cannot be a direct child of 'stages'; it must be inside a 'stage' block
Attempts:
2 left
💡 Hint

Check the Jenkins pipeline syntax rules for where parallel can be placed.

🔀 Workflow
advanced
2:30remaining
What is the order of execution for these stages in a Jenkins pipeline?

Consider this Jenkins pipeline snippet:

pipeline {
  agent any
  stages {
    stage('Build') {
      steps { echo 'Build' }
    }
    stage('Test') {
      parallel {
        stage('Unit') {
          steps { echo 'Unit Test' }
        }
        stage('Integration') {
          steps { echo 'Integration Test' }
        }
      }
    }
    stage('Deploy') {
      steps { echo 'Deploy' }
    }
  }
}

What is the correct order of printed messages in the Jenkins console?

Jenkins
pipeline {
  agent any
  stages {
    stage('Build') {
      steps { echo 'Build' }
    }
    stage('Test') {
      parallel {
        stage('Unit') {
          steps { echo 'Unit Test' }
        }
        stage('Integration') {
          steps { echo 'Integration Test' }
        }
      }
    }
    stage('Deploy') {
      steps { echo 'Deploy' }
    }
  }
}
ABuild, Unit Test and Integration Test (in any order), Deploy
BUnit Test, Integration Test, Build, Deploy
CBuild, Deploy, Unit Test, Integration Test
DBuild, Unit Test, Deploy, Integration Test
Attempts:
2 left
💡 Hint

Remember that parallel stages run simultaneously after the previous stage completes.

Best Practice
expert
3:00remaining
Which stage block structure ensures proper error handling and cleanup?

In Jenkins declarative pipelines, which stage block structure correctly uses post blocks to handle success and cleanup after a stage?

A
stage('Deploy') {
  post {
    success {
      echo 'Deployment succeeded'
    }
    always {
      echo 'Cleanup'
    }
  }
  steps {
    echo 'Deploying'
  }
}
B
stage('Deploy') {
  steps {
    echo 'Deploying'
  }
  post {
    success {
      echo 'Deployment succeeded'
    }
    always {
      echo 'Cleanup'
    }
  }
}
C
stage('Deploy') {
  steps {
    echo 'Deploying'
  }
  post {
    always {
      echo 'Cleanup'
    }
    success {
      echo 'Deployment succeeded'
    }
  }
}
D
stage('Deploy') {
  steps {
    echo 'Deploying'
  }
  post {
    failure {
      echo 'Deployment failed'
    }
  }
}
Attempts:
2 left
💡 Hint

The order of post conditions matters for readability and correctness.