Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-47091

Multibranch pipeline does not build GitHub pull requests destined for single branch

    • Icon: New Feature New Feature
    • Resolution: Fixed
    • Icon: Trivial Trivial
    • scm-api-plugin
    • None

      I have configured a multibranch job to only find a single branch (because that's what I want). Really, the only reason I'm using multi-branch at all is for pull request functionality in pipelines.

      Unfortunately, multi-branch does not appear to detect pull requests to master. Maybe because of the branch specifier? I don't consider this working as designed. The intent here is to build pull requests destined for the master branch regardless of what the branch name might be.

      I have attached a sample config.xml, a screenshot, and the indexing log from the multibranch job. Please see environment for master and plugin versions.

          [JENKINS-47091] Multibranch pipeline does not build GitHub pull requests destined for single branch

          Sam Gleske added a comment - - edited

          It was easy thanks to your advice, for me the biggest hurdle was how to create a plugin. This was my first plugin so it must not have been too big of a hurdle. I'll work on adding some tests and filing that jenkinsci hosting request once I'm ready.

          Sam Gleske added a comment - - edited It was easy thanks to your advice, for me the biggest hurdle was how to create a plugin. This was my first plugin so it must not have been too big of a hurdle. I'll work on adding some tests and filing that jenkinsci hosting request once I'm ready.

          Sam Gleske added a comment -

          stephenconnolly how do I do the following with the filter?

          EnvVars env = build.getEnvironment(listener));
          

          I would like to inject an environment variable IS_PR_BUILD so one could use it in scripts if desired.

          Sam Gleske added a comment - stephenconnolly how do I do the following with the filter? EnvVars env = build.getEnvironment(listener)); I would like to inject an environment variable IS_PR_BUILD so one could use it in scripts if desired.

          Stephen Connolly added a comment - But you already have CHANGE_ID if the SCMHead is a PR: https://github.com/jenkinsci/branch-api-plugin/blob/master/src/main/java/jenkins/branch/BranchNameContributor.java#L65

          Sam Gleske added a comment - - edited

          I did not realize that. I'll add IS_PR_BUILD to my personal pipeline global library based on the existence of CHANGE_ID. The idea is for it to be true or false so shell scripts can simply:

          if ${IS_PULL_REQUEST}; then
            #do something because it's a pull request
          fi
          

          Sam Gleske added a comment - - edited I did not realize that. I'll add IS_PR_BUILD to my personal pipeline global library based on the existence of CHANGE_ID. The idea is for it to be true or false so shell scripts can simply: if ${IS_PULL_REQUEST}; then #do something because it's a pull request fi

          Stephen Connolly added a comment - - edited

          Not exactly clear to me what the gain in all that hassle is over

          if [ -n "${CHANGE_ID}" ] ; then
            # do something because it's a pull request
          fi
          

          Stephen Connolly added a comment - - edited Not exactly clear to me what the gain in all that hassle is over if [ -n "${CHANGE_ID}" ] ; then # do something because it's a pull request fi

          Sam Gleske added a comment -

          It just simplifies bash scripting. It's not something that needs to be included in this plugin. I was able to update my scripts since you pointed that out to me. https://github.com/samrocketman/jervis/commit/315c20eb5e2a4ec8e468f0dac3534282ff04a4f0

          Sam Gleske added a comment - It just simplifies bash scripting. It's not something that needs to be included in this plugin. I was able to update my scripts since you pointed that out to me. https://github.com/samrocketman/jervis/commit/315c20eb5e2a4ec8e468f0dac3534282ff04a4f0

          Sam Gleske added a comment -

          stephenconnolly I went ahead and documented this in the plugin wiki page. https://wiki.jenkins.io/display/JENKINS/SCM+Branch+PR+Filter+Plugin

          Sam Gleske added a comment - stephenconnolly I went ahead and documented this in the plugin wiki page. https://wiki.jenkins.io/display/JENKINS/SCM+Branch+PR+Filter+Plugin

          sag47 I suspect abayer might be able to advise you on better examples of testing for PRs to provide on your Wiki page. Certainly there is a better way for declarative style... but I also think that your non-declarative style example is over-egged

          Stephen Connolly added a comment - sag47 I suspect abayer might be able to advise you on better examples of testing for PRs to provide on your Wiki page. Certainly there is a better way for declarative style... but I also think that your non-declarative style example is over-egged

          Sam Gleske added a comment -

          Feel free to update it; it's a wiki

          Sam Gleske added a comment - Feel free to update it; it's a wiki

          Sam Gleske added a comment -

          This issue has been resolved with the creation of a new plugin: https://wiki.jenkins.io/display/JENKINS/SCM+Filter+Branch+PR+Plugin

          Sam Gleske added a comment - This issue has been resolved with the creation of a new plugin: https://wiki.jenkins.io/display/JENKINS/SCM+Filter+Branch+PR+Plugin

            sag47 Sam Gleske
            sag47 Sam Gleske
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: