Bird
Raised Fist0
Jenkinsdevops~10 mins

CI/CD pipeline mental model in Jenkins - Interactive Code Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a Jenkins pipeline that starts with the 'Build' stage.

Jenkins
pipeline {
  agent any
  stages {
    stage('Build') {
      steps {
        [1] 'echo Building the project'
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
Ash
Bscript
Cinput
Dstage
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'script' instead of 'sh' to run shell commands.
2fill in blank
medium

Complete the code to add a 'Test' stage after the 'Build' stage in the Jenkins pipeline.

Jenkins
pipeline {
  agent any
  stages {
    stage('Build') {
      steps {
        sh 'echo Building the project'
      }
    }
    stage('[1]') {
      steps {
        sh 'echo Running tests'
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
ADeploy
BPackage
CBuild
DTest
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Deploy' or 'Package' instead of 'Test' for the testing stage.
3fill in blank
hard

Fix the error in the Jenkins pipeline code by completing the missing keyword for parallel stages.

Jenkins
pipeline {
  agent any
  stages {
    stage('Build and Test') {
      [1] {
        stage('Build') {
          steps {
            sh 'echo Building'
          }
        }
        stage('Test') {
          steps {
            sh 'echo Testing'
          }
        }
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
Aparallel
Bsteps
Cscript
Dagent
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'steps' or 'script' instead of 'parallel' for concurrent stages.
4fill in blank
hard

Fill both blanks to create a Jenkins pipeline stage that runs only when the branch is 'main'.

Jenkins
pipeline {
  agent any
  stages {
    stage('Deploy') {
      when {
        [1] '[2]'
      }
      steps {
        sh 'echo Deploying to production'
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
Abranch
Benvironment
Cmain
Dfeature
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'environment' instead of 'branch' in the when condition.
5fill in blank
hard

Fill all three blanks to create a Jenkins pipeline that defines an environment variable and uses it in a shell command.

Jenkins
pipeline {
  agent any
  environment {
    [1] = '[2]'
  }
  stages {
    stage('Print Env') {
      steps {
        sh 'echo [3]'
      }
    }
  }
}
Drag options to blanks, or click blank then click option'
AGREETING
BHello, World!
C$GREETING
DMESSAGE
Attempts:
3 left
💡 Hint
Common Mistakes
Using the variable name without the $ sign in the shell command.

Practice

(1/5)
1. What is the main purpose of a CI/CD pipeline in Jenkins?
easy
A. To manually run tests on software
B. To store software documentation
C. To write code faster
D. To automate building, testing, and deploying software

Solution

  1. Step 1: Understand CI/CD pipeline role

    A CI/CD pipeline automates the process of building, testing, and deploying software to make delivery faster and more reliable.
  2. Step 2: Identify Jenkins pipeline function

    Jenkins pipelines organize these automation steps into stages for clarity and control.
  3. Final Answer:

    To automate building, testing, and deploying software -> Option D
  4. Quick Check:

    CI/CD pipeline purpose = Automate build, test, deploy [OK]
Hint: CI/CD means automate build, test, deploy steps [OK]
Common Mistakes:
  • Thinking CI/CD is for manual testing only
  • Confusing pipeline with code writing
  • Assuming pipeline stores documentation
2. Which of the following is the correct syntax to define a stage in a Jenkins declarative pipeline?
easy
A. stage: Build { steps: { echo 'Building...' } }
B. stage('Build') { steps { echo 'Building...' } }
C. stage = 'Build' { steps { echo 'Building...' } }
D. stage('Build') => { steps { echo 'Building...' } }

Solution

  1. Step 1: Recall Jenkins declarative pipeline syntax

    In Jenkins declarative pipelines, stages are defined using stage('Name') { ... } syntax.
  2. Step 2: Check each option's syntax

    stage('Build') { steps { echo 'Building...' } } uses correct syntax with parentheses and braces. Options B, C, and D use invalid symbols or assignment.
  3. Final Answer:

    stage('Build') { steps { echo 'Building...' } } -> Option B
  4. Quick Check:

    Correct stage syntax uses parentheses and braces [OK]
Hint: Stages use stage('name') { steps { ... } } syntax [OK]
Common Mistakes:
  • Using colons instead of parentheses
  • Assigning stage with = instead of defining block
  • Using arrow => instead of braces
3. Given this Jenkins pipeline snippet, what will be the output?
pipeline {
  agent any
  stages {
    stage('Test') {
      steps {
        echo 'Starting tests'
        echo 'Tests passed'
      }
    }
  }
}
medium
A. Starting tests only
B. Tests passed\nStarting tests
C. Starting tests\nTests passed
D. No output, pipeline fails

Solution

  1. Step 1: Analyze the pipeline steps

    The 'Test' stage has two echo commands executed in order: first 'Starting tests', then 'Tests passed'.
  2. Step 2: Determine output order

    Jenkins runs steps sequentially, so output will be 'Starting tests' followed by 'Tests passed'.
  3. Final Answer:

    Starting tests\nTests passed -> Option C
  4. Quick Check:

    Echo commands run in order = Starting tests then Tests passed [OK]
Hint: Steps run top to bottom inside stage [OK]
Common Mistakes:
  • Assuming output order is reversed
  • Thinking only first echo runs
  • Believing pipeline fails without error
4. Identify the error in this Jenkins pipeline snippet:
pipeline {
  agent any
  stages {
    stage('Build')
      steps {
        echo 'Building...'
      }
  }
}
medium
A. Missing braces { } after stage('Build') declaration
B. Incorrect agent declaration
C. Missing echo command inside steps
D. Pipeline missing post section

Solution

  1. Step 1: Check stage syntax

    The stage block must have braces { } after the stage name to enclose steps.
  2. Step 2: Identify missing braces

    Here, stage('Build') is not followed by { }, causing a syntax error.
  3. Final Answer:

    Missing braces { } after stage('Build') declaration -> Option A
  4. Quick Check:

    Stage requires braces after name [OK]
Hint: Stage must have braces { } after name [OK]
Common Mistakes:
  • Ignoring missing braces error
  • Thinking agent declaration is wrong
  • Assuming post section is mandatory
5. You want to create a Jenkins pipeline that builds your app only if tests pass. Which pipeline structure correctly models this CI/CD mental flow?
hard
A. stages { stage('Test') { steps { echo 'Testing...' } } stage('Build') { steps { echo 'Building...' } } }
B. stages { stage('Build') { steps { echo 'Building...' } } stage('Test') { steps { echo 'Testing...' } } }
C. stages { stage('Build') { steps { echo 'Building...' } } post { always { echo 'Tests passed' } } }
D. stages { stage('Test') { steps { echo 'Testing...' } } stage('Build') { steps { echo 'Building...' } } post { failure { error 'Tests failed' } } }

Solution

  1. Step 1: Understand the requirement

    The app should build only if tests pass, requiring Test stage before Build stage to model the CI/CD flow where build follows successful tests.
  2. Step 2: Analyze pipeline options

    stages { stage('Test') { steps { echo 'Testing...' } } stage('Build') { steps { echo 'Building...' } } } places testing before building, correctly modeling the flow.
  3. Step 3: Confirm other options

    stages { stage('Build') { steps { echo 'Building...' } } stage('Test') { steps { echo 'Testing...' } } } builds before tests (wrong order). stages { stage('Build') { steps { echo 'Building...' } } post { always { echo 'Tests passed' } } } wrong order and invalid post inside stages (syntax error). stages { stage('Test') { steps { echo 'Testing...' } } stage('Build') { steps { echo 'Building...' } } post { failure { error 'Tests failed' } } } invalid post inside stages (syntax error).
  4. Final Answer:

    stages { stage('Test') { steps { echo 'Testing...' } } stage('Build') { steps { echo 'Building...' } } } -> Option A
  5. Quick Check:

    Test stage before Build = correct CI/CD order [OK]
Hint: Test stage before build stage [OK]
Common Mistakes:
  • Building before testing
  • Placing post inside stages (syntax error)
  • Wrong order with post always
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard