Bird
Raised Fist0
Jenkinsdevops~20 mins

Post-build actions in Jenkins - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Post-build Pro
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Understanding Post-build Actions in Jenkins

Which of the following best describes the purpose of post-build actions in a Jenkins job?

AThey specify tasks that run after the build completes, such as notifications or archiving artifacts.
BThey define the steps to compile and build the source code before testing.
CThey configure the source code repository and branch to build from.
DThey set environment variables used during the build process.
Attempts:
2 left
💡 Hint

Think about what happens after the build finishes successfully or fails.

💻 Command Output
intermediate
1:30remaining
Result of Archiving Artifacts Post-build

After configuring a Jenkins job to archive the file output.log as a post-build action, what will you see in the Jenkins job page after a successful build?

AThe <code>output.log</code> file will be available for download under the 'Archived Artifacts' section.
BThe build will fail because archiving is not allowed in post-build actions.
CThe <code>output.log</code> file will be deleted from the workspace automatically.
DThe console output will include the contents of <code>output.log</code>.
Attempts:
2 left
💡 Hint

Archiving artifacts means saving files for later access from the build page.

🔀 Workflow
advanced
2:00remaining
Configuring Email Notification as a Post-build Action

You want Jenkins to send an email notification only when a build fails. Which post-build action configuration achieves this?

AAdd 'Post-build Script' to run a shell command that sends email regardless of build status.
BAdd 'Editable Email Notification' post-build action and set triggers to 'Failure'.
CAdd 'Send Email' build step before the build starts.
DAdd 'Email Notification' post-build action and leave triggers empty.
Attempts:
2 left
💡 Hint

Look for a post-build action that supports conditional triggers.

❓ Troubleshoot
advanced
2:00remaining
Troubleshooting Post-build Action Failure

A Jenkins job's post-build action to archive artifacts is not working; no files appear under 'Archived Artifacts' after a successful build. What is the most likely cause?

AThe build steps did not run because the job was disabled.
BThe Jenkins master node is offline.
CThe file pattern specified for archiving does not match any files in the workspace.
DThe post-build action is configured before the build steps.
Attempts:
2 left
💡 Hint

Check if the files you want to archive actually exist after the build.

✅ Best Practice
expert
2:30remaining
Best Practice for Post-build Actions in Pipeline Scripts

In a Jenkins Pipeline script, which is the best way to ensure a post-build action runs regardless of build success or failure?

APlace the post-build action commands at the start of the <code>pipeline</code> block.
BAdd post-build actions only in the Jenkins job configuration UI, not in the pipeline script.
CUse <code>try { ... } catch { ... }</code> blocks inside the <code>stages</code> to run post-build actions.
DUse the <code>post { always { ... } }</code> block to define actions that always run after the build.
Attempts:
2 left
💡 Hint

Look for a pipeline syntax that guarantees execution after all stages.

Practice

(1/5)
1. What is the main purpose of Post-build actions in Jenkins?
easy
A. To start the build process
B. To write the build script
C. To perform tasks automatically after the build finishes
D. To configure the Jenkins server settings

Solution

  1. Step 1: Understand Jenkins build phases

    Jenkins runs build steps first, then post-build actions after the build ends.
  2. Step 2: Identify the role of post-build actions

    Post-build actions automate tasks like notifications, archiving, or cleanup after the build completes.
  3. Final Answer:

    To perform tasks automatically after the build finishes -> Option C
  4. Quick Check:

    Post-build actions = tasks after build [OK]
Hint: Post-build actions run after build ends to automate tasks [OK]
Common Mistakes:
  • Confusing post-build actions with build steps
  • Thinking post-build actions start the build
  • Assuming post-build actions configure Jenkins server
2. Which of the following is the correct syntax to add a post-build action in a Jenkins pipeline script?
easy
A. build { post { echo 'Build finished' } }
B. pipeline { postbuild { echo 'Build finished' } }
C. steps { post { echo 'Build finished' } }
D. post { always { echo 'Build finished' } }

Solution

  1. Step 1: Recall Jenkins pipeline post syntax

    In declarative pipelines, post block defines post-build actions with conditions like always.
  2. Step 2: Match syntax options

    post { always { echo 'Build finished' } } uses correct post { always { ... } } syntax. Others use invalid blocks like build or postbuild.
  3. Final Answer:

    post { always { echo 'Build finished' } } -> Option D
  4. Quick Check:

    Post block syntax = post { always { echo 'Build finished' } } [OK]
Hint: Use 'post { always { ... } }' for post-build actions in pipeline [OK]
Common Mistakes:
  • Using 'postbuild' instead of 'post'
  • Placing post block inside 'steps'
  • Using 'build' block incorrectly
3. Given this Jenkins pipeline snippet, what will be printed after the build finishes successfully?
pipeline {
  agent any
  stages {
    stage('Build') {
      steps {
        echo 'Building...'
      }
    }
  }
  post {
    success {
      echo 'Build succeeded!'
    }
    failure {
      echo 'Build failed!'
    }
  }
}
medium
A. Building... Build failed!
B. Building... Build succeeded!
C. Build succeeded!
D. Build failed!

Solution

  1. Step 1: Analyze build steps

    The pipeline prints 'Building...' during the build stage.
  2. Step 2: Check post-build actions on success

    On successful build, the success block runs, printing 'Build succeeded!'.
  3. Final Answer:

    Building... Build succeeded! -> Option B
  4. Quick Check:

    Success post block runs after build [OK]
Hint: Success block runs only if build succeeds [OK]
Common Mistakes:
  • Confusing failure block with success block
  • Ignoring initial build echo
  • Assuming post block runs before build
4. You wrote this Jenkins pipeline post section but the notification never sends on build failure:
post {
  failure {
    mail(to: 'team@example.com', subject: 'Build Failed')
  }
}
What is the likely problem?
medium
A. The mail step requires proper Jenkins email configuration
B. The failure block should be inside steps
C. The mail step requires a steps block inside failure
D. The post block must be inside steps

Solution

  1. Step 1: Understand the mail step requirements

    The mail step requires the 'Email Extension Plugin' to be installed and SMTP server configured in Manage Jenkins > Configure System > Extended E-mail Notification.
  2. Step 2: Identify the likely problem

    Without proper email configuration (SMTP host, port, credentials, etc.), the notification won't send even if the syntax is correct.
  3. Final Answer:

    The mail step requires proper Jenkins email configuration -> Option A
  4. Quick Check:

    Mail needs SMTP config [OK]
Hint: Configure SMTP in Jenkins for mail step [OK]
Common Mistakes:
  • Not installing Email Extension plugin
  • Not setting SMTP server details
  • Missing 'from' address or credentials
5. You want to archive build artifacts only if the build succeeds and always send a notification email regardless of build result. Which Jenkins pipeline post section correctly implements this?
hard
A. post { success { archiveArtifacts 'build/*.jar' } always { mail(to: 'devs@example.com', subject: 'Build Notification') } }
B. post { always { archiveArtifacts 'build/*.jar' mail(to: 'devs@example.com', subject: 'Build Notification') } }
C. post { success { archiveArtifacts 'build/*.jar' mail(to: 'devs@example.com', subject: 'Build Notification') } }
D. post { failure { archiveArtifacts 'build/*.jar' } always { mail(to: 'devs@example.com', subject: 'Build Notification') } }

Solution

  1. Step 1: Identify conditions for each action

    Archiving should happen only on success, so it goes inside success. Email should always send, so it goes inside always.
  2. Step 2: Match options with conditions

    post { success { archiveArtifacts 'build/*.jar' } always { mail(to: 'devs@example.com', subject: 'Build Notification') } } correctly separates archive in success and mail in always. Others mix conditions incorrectly.
  3. Final Answer:

    post { success { archiveArtifacts 'build/*.jar' } always { mail(to: 'devs@example.com', subject: 'Build Notification') } } -> Option A
  4. Quick Check:

    Use success for archive, always for mail [OK]
Hint: Use 'success' for archive, 'always' for notifications [OK]
Common Mistakes:
  • Putting archive in always block
  • Sending mail only on success
  • Archiving on failure instead of 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