Bird
Raised Fist0
Jenkinsdevops~10 mins

Build steps execution 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 simple Jenkins pipeline stage named 'Build'.

Jenkins
stage('Build') {
    steps {
        [1] 'echo Building the project'
    }
}
Drag options to blanks, or click blank then click option'
Ascript
Bsh
Cexecute
Drun
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'run' or 'execute' which are not Jenkins pipeline steps.
2fill in blank
medium

Complete the code to add a stage named 'Test' that runs a shell command.

Jenkins
stage('Test') {
    steps {
        [1] 'echo Running tests'
    }
}
Drag options to blanks, or click blank then click option'
Abat
Bcmd
Cpowershell
Dsh
Attempts:
3 left
💡 Hint
Common Mistakes
Using Windows-specific steps like 'bat' on Unix agents.
3fill in blank
hard

Fix the error in the pipeline code to correctly define a stage named 'Deploy'.

Jenkins
stage('Deploy') {
    [1] {
        sh 'echo Deploying application'
    }
}
Drag options to blanks, or click blank then click option'
Acommands
Bscript
Csteps
Dactions
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'script' or 'commands' which are not valid block names here.
4fill in blank
hard

Fill both blanks to create a pipeline with two stages: 'Build' and 'Test', each running a shell command.

Jenkins
pipeline {
    agent any
    stages {
        stage('Build') {
            [1] {
                sh 'echo Building'
            }
        }
        stage('Test') {
            [2] {
                sh 'echo Testing'
            }
        }
    }
}
Drag options to blanks, or click blank then click option'
Asteps
Bscript
Ccommands
Dactions
Attempts:
3 left
💡 Hint
Common Mistakes
Using different or invalid block names like 'script' or 'commands'.
5fill in blank
hard

Fill all three blanks to create a pipeline with stages 'Build', 'Test', and 'Deploy', each running a shell command.

Jenkins
pipeline {
    agent any
    stages {
        stage('Build') {
            [1] {
                sh 'echo Build started'
            }
        }
        stage('Test') {
            [2] {
                sh 'echo Test started'
            }
        }
        stage('Deploy') {
            [3] {
                sh 'echo Deploy started'
            }
        }
    }
}
Drag options to blanks, or click blank then click option'
Asteps
Bscript
Ccommands
Dactions
Attempts:
3 left
💡 Hint
Common Mistakes
Using different block names for different stages.

Practice

(1/5)
1. What is the main purpose of build steps in a Jenkins pipeline?
easy
A. To manage Jenkins plugins and updates
B. To create user accounts on the Jenkins server
C. To monitor server hardware performance
D. To run commands that compile, test, and package software automatically

Solution

  1. Step 1: Understand what build steps do

    Build steps are commands executed during a Jenkins pipeline to automate tasks.
  2. Step 2: Identify the correct purpose

    They help compile, test, and package software automatically as part of the build process.
  3. Final Answer:

    To run commands that compile, test, and package software automatically -> Option D
  4. Quick Check:

    Build steps = automate build tasks [OK]
Hint: Build steps automate software tasks in order [OK]
Common Mistakes:
  • Confusing build steps with server management
  • Thinking build steps create users
  • Assuming build steps monitor hardware
2. Which of the following is the correct syntax to add a shell build step in a Jenkins pipeline script?
easy
A. sh 'echo Hello World'
B. shell: echo Hello World
C. execute shell { echo Hello World }
D. run shell echo Hello World

Solution

  1. Step 1: Recall Jenkins pipeline shell step syntax

    In Jenkins scripted or declarative pipelines, shell commands run with the sh step and a string argument.
  2. Step 2: Match the correct syntax

    The correct syntax is sh 'command', so sh 'echo Hello World' is valid.
  3. Final Answer:

    sh 'echo Hello World' -> Option A
  4. Quick Check:

    Shell step uses sh 'command' [OK]
Hint: Use sh 'command' for shell steps in Jenkins [OK]
Common Mistakes:
  • Using incorrect keywords like shell: or execute shell
  • Omitting quotes around the command
  • Writing commands without the sh step
3. Given this Jenkins pipeline snippet, what will be the output in the console?
stage('Build') {
  steps {
    sh 'echo Start Build'
    sh 'echo Build Complete'
  }
}
medium
A. Start Build only
B. Build Complete\nStart Build
C. Start Build\nBuild Complete
D. No output, commands are skipped

Solution

  1. Step 1: Understand step execution order

    Jenkins runs build steps in the order they appear inside the stage.
  2. Step 2: Trace the commands

    First, echo Start Build runs, printing "Start Build". Then echo Build Complete runs, printing "Build Complete".
  3. Final Answer:

    Start Build\nBuild Complete -> Option C
  4. Quick Check:

    Steps run in order, output matches [OK]
Hint: Steps run top to bottom inside stages [OK]
Common Mistakes:
  • Assuming steps run in reverse order
  • Thinking only first step outputs
  • Believing steps might be skipped without error
4. You have this Jenkins pipeline snippet:
stage('Test') {
  steps {
    sh 'echo Running tests'
    sh 'exit 1'
    sh 'echo Tests done'
  }
}
What will happen when this pipeline runs?
medium
A. All commands run, including 'echo Tests done'
B. Pipeline stops at 'exit 1' and 'echo Tests done' is not executed
C. Pipeline ignores 'exit 1' and continues
D. Pipeline skips 'echo Running tests' and runs others

Solution

  1. Step 1: Understand shell step failure behavior

    In Jenkins, if a shell command returns a non-zero exit code (like exit 1), the pipeline fails and stops executing further steps.
  2. Step 2: Analyze the commands

    After sh 'exit 1' fails, the next step sh 'echo Tests done' will not run.
  3. Final Answer:

    Pipeline stops at 'exit 1' and 'echo Tests done' is not executed -> Option B
  4. Quick Check:

    Non-zero exit stops pipeline [OK]
Hint: Non-zero exit code stops pipeline steps [OK]
Common Mistakes:
  • Assuming pipeline continues after failure
  • Thinking all steps always run
  • Ignoring exit codes in shell steps
5. You want to run two build steps in a Jenkins pipeline: first compile code, then run tests only if compile succeeds. Which pipeline snippet correctly implements this?
hard
A. stage('Build') { steps { sh 'compile.sh' script { if (currentBuild.result != 'FAILURE') { sh 'test.sh' } } } }
B. stage('Build') { steps { sh 'compile.sh || true' sh 'test.sh' } }
C. stage('Build') { steps { sh 'compile.sh' } } stage('Test') { steps { sh 'test.sh' } }
D. } } 'hs.tset' hs 'eurt || hs.elipmoc' hs { spets { )'dliuB'(egats

Solution

  1. Step 1: Understand conditional execution in Jenkins pipeline

    To run tests only if compile succeeds, you need to check the build status before running tests.
  2. Step 2: Analyze options

    stage('Build') { steps { sh 'compile.sh' script { if (currentBuild.result != 'FAILURE') { sh 'test.sh' } } } } uses a script block to check if the build is not failed before running tests, ensuring tests run only after successful compile.
  3. Final Answer:

    sh 'compile.sh'; script { if (currentBuild.result != 'FAILURE') { sh 'test.sh' } } -> Option A
  4. Quick Check:

    Conditional test run uses script and build status check [OK]
Hint: Use script block to conditionally run steps [OK]
Common Mistakes:
  • Running all steps unconditionally
  • Using shell || true which ignores compile failure
  • Splitting stages without controlling flow
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