0
0
Jenkinsdevops~10 mins

Pull request builds in Jenkins - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Pull request builds
Developer creates PR
PR triggers Jenkins build
Jenkins checks out PR code
Run build and tests
Build success?
NoReport failure to PR
Yes
Report success to PR
PR can be merged
This flow shows how a pull request triggers a Jenkins build, runs tests, and reports results back to the PR.
Execution Sample
Jenkins
pipeline {
  agent any
  triggers {
    githubPullRequest()
  }
  stages {
    stage('Build and Test') {
      steps {
        sh 'make test'
      }
    }
  }
}
A Jenkins pipeline triggered by pull requests that runs tests on the PR code.
Process Table
StepActionEvaluationResult
1PR created in GitHubPR event detectedTrigger Jenkins build
2Jenkins checks out PR branchCheckout successReady to build
3Run 'make test'Tests pass?Yes
4Report build statusSend success to GitHubPR marked as successful
5PR merge allowedNo conflicts, tests passedPR can be merged
6If tests failReport failure to GitHubPR marked as failed, merge blocked
💡 Build ends after reporting status to GitHub and allowing or blocking merge.
Status Tracker
VariableStartAfter Step 2After Step 3After Step 4Final
PR StatusOpenChecked outTests passedSuccess reportedMerge allowed
Build StatusNot startedRunningPassedReportedComplete
Key Moments - 3 Insights
Why does Jenkins need to check out the PR branch instead of the main branch?
Jenkins checks out the PR branch to test the exact code changes in the pull request, as shown in step 2 of the execution table.
What happens if the tests fail during the build?
If tests fail (step 6), Jenkins reports failure back to GitHub and blocks the PR from merging, preventing broken code from entering main.
How does Jenkins know when to trigger a build for a pull request?
Jenkins listens for pull request events from GitHub (step 1), which triggers the build automatically.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the build status after step 3?
AFailed
BPassed
CNot started
DReported
💡 Hint
Check the 'Build Status' variable after step 3 in the variable_tracker.
At which step does Jenkins report the build result back to GitHub?
AStep 2
BStep 3
CStep 4
DStep 5
💡 Hint
Look for the action 'Report build status' in the execution_table.
If the tests fail, what is the effect on the pull request according to the execution flow?
APR is marked as failed and merge is blocked
BBuild is retried automatically
CPR is merged anyway
DNothing happens
💡 Hint
Refer to step 6 in the execution_table and key_moments about test failure.
Concept Snapshot
Pull request builds trigger Jenkins to test PR code.
Jenkins checks out the PR branch, runs tests.
Build results are reported back to GitHub.
Success allows merge; failure blocks it.
Automates quality checks before merging code.
Full Transcript
When a developer creates a pull request, Jenkins detects this event and triggers a build. Jenkins then checks out the pull request branch to get the exact code changes. It runs the build and tests, such as 'make test'. If the tests pass, Jenkins reports success back to GitHub, marking the PR as successful and allowing it to be merged. If tests fail, Jenkins reports failure and blocks the merge to keep the main branch stable. This process automates quality checks on code changes before they are merged.