Bird
Raised Fist0
Jenkinsdevops~20 mins

Build, test, deploy stages concept in Jenkins - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Build-Test-Deploy Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Purpose of the 'Build' stage in Jenkins pipeline

In a Jenkins pipeline with stages named 'Build', 'Test', and 'Deploy', what is the main purpose of the 'Build' stage?

AMonitor application performance after deployment
BRun automated tests to verify code correctness
CDeploy the application to production servers
DCompile source code and create executable artifacts
Attempts:
2 left
💡 Hint

Think about what happens before testing and deployment.

💻 Command Output
intermediate
2:00remaining
Output of Jenkins pipeline stage execution

Given this Jenkins pipeline snippet, what will be the output when the 'Test' stage runs successfully?

Jenkins
pipeline {
  agent any
  stages {
    stage('Build') {
      steps {
        echo 'Building the project'
      }
    }
    stage('Test') {
      steps {
        echo 'Running tests'
      }
    }
    stage('Deploy') {
      steps {
        echo 'Deploying application'
      }
    }
  }
}
A[Pipeline] stage\n[Pipeline] { (Build)\n[Pipeline] echo\nRunning tests\n[Pipeline] }
B[Pipeline] stage\n[Pipeline] { (Test)\n[Pipeline] echo\nRunning tests\n[Pipeline] }
C[Pipeline] stage\n[Pipeline] { (Deploy)\n[Pipeline] echo\nRunning tests\n[Pipeline] }
D[Pipeline] stage\n[Pipeline] { (Test)\n[Pipeline] echo\nBuilding the project\n[Pipeline] }
Attempts:
2 left
💡 Hint

Look carefully at which stage is running and what message it prints.

❓ Configuration
advanced
2:30remaining
Correct Jenkinsfile syntax for sequential stages

Which Jenkinsfile snippet correctly defines sequential 'Build', 'Test', and 'Deploy' stages?

A
pipeline {
  agent any
  stages {
    steps {
      stage('Build') { echo 'Build' }
      stage('Test') { echo 'Test' }
      stage('Deploy') { echo 'Deploy' }
    }
  }
}
B
pipeline {
  agent any
  stage('Build') {
    steps { echo 'Build' }
  }
  stage('Test') {
    steps { echo 'Test' }
  }
  stage('Deploy') {
    steps { echo 'Deploy' }
  }
}
C
pipeline {
  agent any
  stages {
    stage('Build') {
      steps { echo 'Build' }
    }
    stage('Test') {
      steps { echo 'Test' }
    }
    stage('Deploy') {
      steps { echo 'Deploy' }
    }
  }
}
D
pipeline {
  agent any
  stages {
    stage('Build') {
      steps { echo 'Build' }
    }
    stage('Test') {
      steps { echo 'Deploy' }
    }
    stage('Deploy') {
      steps { echo 'Test' }
    }
  }
}
Attempts:
2 left
💡 Hint

Remember the correct nesting of stages and stage blocks.

🔀 Workflow
advanced
1:30remaining
Jenkins pipeline stage execution order

In a Jenkins pipeline with stages 'Build', 'Test', and 'Deploy', what is the correct order of execution?

ABuild → Test → Deploy
BTest → Build → Deploy
CDeploy → Build → Test
DDeploy → Test → Build
Attempts:
2 left
💡 Hint

Think about what must happen before testing and deploying.

❓ Troubleshoot
expert
2:30remaining
Identifying error in Jenkins pipeline stage

Given this Jenkinsfile snippet, what error will occur when running the pipeline?

pipeline {
  agent any
  stages {
    stage('Build') {
      steps {
        echo 'Building'
      }
    }
    stage('Test') {
      step {
        echo 'Testing'
      }
    }
    stage('Deploy') {
      steps {
        echo 'Deploying'
      }
    }
  }
}
ASyntax error: 'step' block is invalid, should be 'steps'
BRuntime error: 'echo' command not found
CPipeline runs successfully with all stages
DError: Missing 'agent' declaration inside 'Test' stage
Attempts:
2 left
💡 Hint

Check the block names inside each stage.

Practice

(1/5)
1. What is the main purpose of splitting a Jenkins pipeline into build, test, and deploy stages?
easy
A. To organize the process into clear steps and catch errors early
B. To run all commands at the same time for speed
C. To skip testing and deploy directly
D. To only build the code without testing or deploying

Solution

  1. Step 1: Understand the purpose of stages

    Stages separate the pipeline into logical parts: building, testing, and deploying.
  2. Step 2: Recognize benefits of stages

    This separation helps find errors early and keeps the process organized.
  3. Final Answer:

    To organize the process into clear steps and catch errors early -> Option A
  4. Quick Check:

    Stages = clear steps + early error detection [OK]
Hint: Stages split work to catch errors early and stay organized [OK]
Common Mistakes:
  • Thinking stages run in parallel by default
  • Skipping test stage to save time
  • Confusing build with deploy
2. Which of the following is the correct syntax to define a build stage in a Jenkins declarative pipeline?
easy
A. stage('build') { steps { sh 'make build' } }
B. build { stage('steps') { sh 'make build' } }
C. steps { stage('build') { sh 'make build' } }
D. pipeline { build { sh 'make build' } }

Solution

  1. Step 1: Recall Jenkins declarative syntax

    A stage is defined as stage('name') { steps { ... } }.
  2. Step 2: Match syntax with options

    stage('build') { steps { sh 'make build' } } correctly uses stage('build') { steps { sh 'make build' } }.
  3. Final Answer:

    stage('build') { steps { sh 'make build' } } -> Option A
  4. Quick Check:

    Stage syntax = stage('name') + steps block [OK]
Hint: Stage syntax: stage('name') { steps { ... } } [OK]
Common Mistakes:
  • Placing steps outside stage block
  • Using build as a block instead of stage
  • Missing steps keyword
3. Given this Jenkins pipeline snippet:
pipeline {
  agent any
  stages {
    stage('build') {
      steps {
        echo 'Building...'
      }
    }
    stage('test') {
      steps {
        error 'Test failed!'
      }
    }
    stage('deploy') {
      steps {
        echo 'Deploying...'
      }
    }
  }
}

What will be the output when this pipeline runs?
medium
A. Pipeline skips build and test, runs deploy only
B. All stages run successfully including deploy
C. Build stage runs, then test stage fails and stops pipeline; deploy does not run
D. Pipeline runs build and deploy but skips test

Solution

  1. Step 1: Analyze build stage

    The build stage prints 'Building...' successfully.
  2. Step 2: Analyze test stage

    The test stage runs error 'Test failed!' which stops the pipeline with failure.
  3. Step 3: Analyze deploy stage

    Because test failed, deploy stage does not run.
  4. Final Answer:

    Build stage runs, then test stage fails and stops pipeline; deploy does not run -> Option C
  5. Quick Check:

    Failure in test stops pipeline before deploy [OK]
Hint: Error in test stage stops pipeline before deploy [OK]
Common Mistakes:
  • Assuming deploy runs despite test failure
  • Thinking error only logs message without stopping
  • Ignoring pipeline stop on error
4. You wrote this Jenkins pipeline snippet:
pipeline {
  agent any
  stages {
    stage('build') {
      steps {
        sh 'make build'
      }
    }
    stage('test') {
      sh 'make test'
    }
    stage('deploy') {
      steps {
        sh 'make deploy'
      }
    }
  }
}

Why does this pipeline fail to run correctly?
medium
A. The build stage uses sh instead of bat
B. The test stage is missing the steps block
C. The deploy stage should be outside stages
D. The agent keyword is misplaced

Solution

  1. Step 1: Check syntax of each stage

    Build and deploy stages have steps { ... } blocks, but test stage does not.
  2. Step 2: Understand Jenkins syntax rules

    Each stage must have a steps block to run commands; missing it causes failure.
  3. Final Answer:

    The test stage is missing the steps block -> Option B
  4. Quick Check:

    Missing steps block in stage = syntax error [OK]
Hint: Every stage needs a steps block for commands [OK]
Common Mistakes:
  • Forgetting steps block inside a stage
  • Mixing shell commands syntax
  • Misplacing agent keyword
5. You want to create a Jenkins pipeline that builds your app, runs tests, and deploys only if tests pass. Which pipeline structure below correctly implements this with proper stages and error handling?
hard
A. pipeline { agent any stages { stage('build') { steps { sh 'build.sh' } } stage('test') { steps { sh 'test.sh' } } stage('deploy') { steps { sh 'deploy.sh' } } } }
B. pipeline { agent any stages { stage('build') { steps { sh 'build.sh' } } stage('test') { steps { sh 'test.sh' } } stage('deploy') { steps { sh 'deploy.sh' } } } post { failure { echo 'Tests failed, skipping deploy' } } }
C. pipeline { agent any stages { stage('build') { steps { sh 'build.sh' } } stage('test') { steps { sh 'test.sh' } } stage('deploy') { steps { sh 'deploy.sh' } } } post { always { echo 'Deploying regardless of test result' } } }
D. pipeline { agent any stages { stage('build') { steps { sh 'build.sh' } } stage('test') { steps { sh 'test.sh' } } stage('deploy') { steps { sh 'deploy.sh' } } } post { success { echo 'Deployment complete' } } }

Solution

  1. Step 1: Understand pipeline flow

    Build runs first, then test, then deploy only if test passes (pipeline success).
  2. Step 2: Analyze post blocks

    pipeline { agent any stages { stage('build') { steps { sh 'build.sh' } } stage('test') { steps { sh 'test.sh' } } stage('deploy') { steps { sh 'deploy.sh' } } } post { success { echo 'Deployment complete' } } } uses post { success { ... } } to confirm deployment success message, matching requirement.
  3. Step 3: Check other options

    pipeline { agent any stages { stage('build') { steps { sh 'build.sh' } } stage('test') { steps { sh 'test.sh' } } stage('deploy') { steps { sh 'deploy.sh' } } } } lacks error handling; B prints message on failure but does not prevent deploy; C deploys always.
  4. Final Answer:

    Option D correctly runs deploy only on success and confirms deployment -> Option D
  5. Quick Check:

    Deploy runs only if tests pass = post success block [OK]
Hint: Use post success block to run deploy only if tests pass [OK]
Common Mistakes:
  • Deploy running even if tests fail
  • Missing post blocks for error handling
  • Confusing post always with success
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