Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Proper configuration for Jenkins GitHub Pull Request Builder downstream

I'm trying to create two Jenkins jobs that both leverage the GitHub Pull Request Builder plugin in order to run multiple status checks, but I'm having trouble getting the status check from my downstream job to show up in my GitHub project.

Here's the summarized CI flow I'd like to setup:

  1. A pull request is opened against my git repository which triggers Upstream job to run in Jenkins
  2. Upstream reports its status based on the build and, if SUCCESS, should invoke Downstream job via a post-build action
  3. Downstream runs and reports its own status check

Step 3 is where I'm having issues. Downstream runs properly, but it does not post a status. The status is not even available under the Branches section of my GitHub project's settings. I'm not sure how GHPRB does the initial creation of the status check, but there are references to the context messaging in the Console Output:

14:58:23 Started by upstream project "upstream" build number 209
14:58:23 originally caused by:
14:58:23  GitHub pull request #114 of commit f1ff2819a5308f7819275e732cf44a2cc2ec31dc, no merge conflicts.
14:58:23 [EnvInject] - Loading node environment variables.
14:58:23 Building on master in workspace /store/jenkins/jobs/downstream/workspace
14:58:23  > git rev-parse --is-inside-work-tree # timeout=10
14:58:23 Fetching changes from the remote Git repository
14:58:23  > git config remote.origin.url <removed for privacy> # timeout=10
14:58:23 Fetching upstream changes from <removed for privacy>
14:58:23  > git --version # timeout=10
14:58:23  > git -c core.askpass=true fetch --tags --progress <removed for privacy> +refs/pull/*:refs/remotes/origin/pr/*
14:58:24  > git rev-parse refs/remotes/origin/master^{commit} # timeout=10
14:58:24  > git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
14:58:24 Checking out Revision eac390c51a1b8b591bfe879421bd5fad0421a1ec (refs/remotes/origin/master)
14:58:24  > git config core.sparsecheckout # timeout=10
14:58:24  > git checkout -f eac390c51a1b8b591bfe879421bd5fad0421a1ec
14:58:24 First time build. Skipping changelog.
14:58:24 [build] $ /store/jenkins/tools/hudson.tasks.Ant_AntInstallation/ant_1.8.2/bin/ant -DghprbStatusUrl= "-DghprbSUCCESSMessage=Packaging organization successfully cleaned" -DghprbStartedStatus=Undeploying -DghprbAddTestResults=false "-DghprbCommitStatusContext=Cleaning Packaging" "-DghprbERRORMessage=An error occurred during undeployment" -DghprbUpstreamStatus=true "-DghprbTriggeredStatus=Preparing destructive changes" "-DghprbFAILUREMessage=Packaging organization failed to clean properly" -DghprbShowMatrixStatus=false

Here are the relevant configuration sections for both Jenkins jobs:


Upstream Job

Source Code Management: Git

  • Name: origin
  • Refspec: +refs/pull/*:refs/remotes/origin/pr/*
  • Branch Specifier: ${sha1}

Build Triggers

  • GitHub Pull Request Builder
    • Use github hooks for build triggering ✔︎
    • Display build errors on downstream builds? ✔︎
    • Trigger Setup is populated with custom context messaging

Post-build Actions

  • Build other projects: Downstream

Downstream Job

Source Code Management: Git

  • Name: origin
  • Refspec: +refs/pull/*:refs/remotes/origin/pr/*
  • Branch Specifier: */master

Build Triggers

  • GitHub Pull Request Builder
    • Trigger Setup is populated with custom context messaging

Build Environment

  • Set GitHub commit status with custom context and message (Must configure upstream job using GHPRB trigger) ✔︎
    • Custom context messaging fields mirror those listed under the Trigger Setup section (I doubt both of these are required, but neither seem to be working currently)

What am I missing? It should be noted that I do not have the Jobs DSL plugin installed so I cannot leverage the extension that GHPRB provides.

like image 698
André Dion Avatar asked Aug 03 '16 14:08

André Dion


People also ask

How can we make Jenkins pipeline jobs triggered by pull requests?

Configure your pipelineOn the Datalog Tagging tab, check “GitHub project”, and put your project URL in the field. On the Build Triggers tab, check “GitHub Pull Request Builder”. Then the GitHub API credentials is automatically filled in. Make sure the Admin list is filled in with at least one admin name.


1 Answers

After extensive trial and error, this comment shed some light on my issue.

The crux of my issue was that Downstream was not receiving required environment variables that GHPRB provides. Namely ghprbGhRepository, ghprbPullId, ghprbActualCommit and sha1.

The correct configurations for both jobs are as follows:


Upstream Job

Source Code Management: Git

  • Name: origin
  • Refspec: +refs/pull/*:refs/remotes/origin/pr/*
  • Branch Specifier: ${sha1}

Build Triggers

  • GitHub Pull Request Builder
    • Use github hooks for build triggering ✔︎
    • Display build errors on downstream builds? ✔︎
    • Trigger Setup is populated with custom context messaging

Build

  • Trigger/call builds on other projects
    • Projects to build: Downstream
    • Predefined parameters:
      • ghprbGhRepository=${ghprbGhRepository}
      • ghprbPullId=${ghprbPullId}
      • ghprbActualCommit=${ghprbActualCommit}
      • sha1=${sha1}

Downstream Job

Source Code Management: Git

  • Name: origin
  • Refspec: +refs/pull/*:refs/remotes/origin/pr/*
  • Branch Specifier: ${sha1}

Build Environment

  • Set GitHub commit status with custom context and message (Must configure upstream job using GHPRB trigger) ✔︎
like image 77
André Dion Avatar answered Oct 08 '22 18:10

André Dion