Interview Prep/Jenkins/Declarative pipeline syntax

How do nested sequential stages work and why are they useful?

IntermediateConceptDeclarative pipeline syntax
Answer

A stage can contain a stages block instead of steps. The child stages run in order and share the parent's agent and workspace, while still appearing individually in the UI.

stage('CI') {
  agent { kubernetes { yamlFile 'ci/build-pod.yaml' } }
  stages {
    stage('Test')  { steps { sh 'npm test' } }
    stage('Build') { steps { sh 'npm run build' } }
  }
}

This is how we combine agent none at the top with one pod for all CI steps.

All Jenkins questions Roadmap: Jenkins

More on Declarative pipeline syntax