0
0
Jenkinsdevops~20 mins

Scripted vs declarative comparison in Jenkins - Practice Questions

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Jenkins Pipeline Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Difference in Pipeline Syntax Style

Which statement correctly describes the main difference between scripted and declarative Jenkins pipelines?

ADeclarative pipelines cannot include parallel stages, but scripted pipelines can.
BDeclarative pipelines require writing Groovy code for all logic, whereas scripted pipelines use YAML files for configuration.
CScripted pipelines are only for building Java projects, while declarative pipelines support all languages.
DScripted pipelines use a Groovy-based imperative programming style, while declarative pipelines use a simpler, predefined syntax focused on stages and steps.
Attempts:
2 left
💡 Hint

Think about how each pipeline style expresses the build process: one is more like writing code, the other more like describing steps.

💻 Command Output
intermediate
2:00remaining
Output of Declarative Pipeline with Parallel Stages

Given this declarative Jenkins pipeline snippet, what will be the output in the Jenkins console log?

pipeline {
  agent any
  stages {
    stage('Build') {
      steps {
        echo 'Building...'
      }
    }
    stage('Test') {
      parallel {
        stage('Unit Tests') {
          steps {
            echo 'Running unit tests'
          }
        }
        stage('Integration Tests') {
          steps {
            echo 'Running integration tests'
          }
        }
      }
    }
  }
}
A
Building...
Running unit tests
Running integration tests
B
Building...
Running unit tests
C
Running unit tests
Running integration tests
Building...
D
Building...
Running integration tests
Attempts:
2 left
💡 Hint

Remember that parallel stages run at the same time, but their output appears sequentially in the log.

Configuration
advanced
2:00remaining
Correct Scripted Pipeline Syntax for Loop

Which scripted Jenkins pipeline snippet correctly loops over a list of environments and echoes each one?

A
def envs = ['dev', 'qa', 'prod']
for (e in envs) {
  echo "Deploying to ${e}"
}
B
def envs = ['dev', 'qa', 'prod']
envs.each() {
  echo 'Deploying to ' + it
}
C
def envs = ['dev', 'qa', 'prod']
for (int i=0; i<envs.size(); i++) {
  echo "Deploying to ${envs[i]}"
}
D
def envs = ['dev', 'qa', 'prod']
for e in envs {
  echo "Deploying to ${e}"
}
Attempts:
2 left
💡 Hint

Check Groovy syntax for loops and list indexing carefully.

Troubleshoot
advanced
2:00remaining
Troubleshooting Declarative Pipeline Syntax Error

Why does this declarative pipeline snippet cause a syntax error?

pipeline {
  agent any
  stages {
    stage('Build') {
      steps {
        echo 'Building...'
      }
    }
    stage('Test') {
      steps {
        parallel {
          unit: {
            echo 'Unit tests'
          },
          integration: {
            echo 'Integration tests'
          }
        }
      }
    }
  }
}
AThe 'parallel' block is incorrectly placed inside 'steps'; it should be directly inside 'stages'.
BThe syntax for parallel stages requires using 'stage' blocks inside 'parallel', not just labels with closures.
CThe parallel stages must be defined as separate 'stage' blocks, not inside 'steps'.
DThe 'parallel' block keys (unit, integration) must be strings in quotes.
Attempts:
2 left
💡 Hint

Check the correct way to define parallel stages in declarative pipelines.

Best Practice
expert
3:00remaining
Choosing Pipeline Style for Complex Logic

You need to implement a Jenkins pipeline with complex conditional logic, loops, and dynamic stage creation. Which pipeline style is best suited for this task and why?

ADeclarative pipeline, because it is simpler and always preferred regardless of complexity.
BDeclarative pipeline, because it has built-in support for complex loops and dynamic stages.
CScripted pipeline, because it allows full Groovy programming capabilities for complex logic and dynamic behavior.
DScripted pipeline, because it uses YAML syntax which is easier for complex logic.
Attempts:
2 left
💡 Hint

Consider which pipeline style supports full programming features like loops and dynamic stage creation.