Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jenkins doesn't build branches when refspec has been defined #77

Closed
deiga opened this issue Jul 16, 2013 · 17 comments · Fixed by #168
Closed

Jenkins doesn't build branches when refspec has been defined #77

deiga opened this issue Jul 16, 2013 · 17 comments · Fixed by #168
Labels

Comments

@deiga
Copy link

deiga commented Jul 16, 2013

I have defined +refs/pull/*:refs/remotes/origin/pr/* as my refspec and ${sha1} as my branch to build.

Now this stops me from building my normal branches when something is pushed to them, how can this be fixed?

I tried setting multiple refspecs but it didn't seem to work, maybe my syntax was wrong...

@janinko
Copy link
Owner

janinko commented Jul 16, 2013

Hi, usually the use case is to have two jobs - one for normal Continuous Integration (in which there is nice history) and one for testing pull requests (in which the history is a mess, eg because of #73).

I only tried to set default value to sha1 parameter to master and it worked, but I didn't tried any other branch. But I believe it should be possible, somehow.

@bilderbuchi
Copy link

As far as I can tell it is now possible to supply multiple refspecs to the Git plugin, separated by space. A quick test so far seems to indicate that, for me, +refs/pull/*:refs/remotes/origin/pr/* +refs/heads/*:refs/remotes/origin/* works as intended (resolving both github push events, and also github PR updates).
Git plugin 2.2.0, Github plugin 1.8, ghprb 1.11.2
See also jenkinsci/git-plugin#166

jdowning added a commit to jdowning/ghprb that referenced this issue Jul 3, 2014
Using the default `refspec` prohibits the project from automatically building non-PR branches like `origin/master`. Prepending the `refspec` with the heads and remote/origin allows the project to build pull requests as well as other branches like `origin/my-feature`. This should resolve jenkinsci#77.

Big thanks to janinko#77 (comment) 😄
@gimler
Copy link

gimler commented Oct 21, 2014

for me it didn't work jenkins starts a build when i commit to my branch 6.0.3 but with the commit hash from the master branch ;(

i use +refs/heads/*:refs/remotes/origin/* +refs/pull/*:refs/remotes/origin/pr/*

any idea? can anybody confirm this?

@emmanuelmathot
Copy link

same issue for me, can someone help?

@KarelCemus
Copy link

I confirm this, still not working

@emmanuelmathot
Copy link

could you reopen that issue since it seems to be still a problem?

@DavidTanner
Copy link
Collaborator

@emmanuelmathot this is an issue with the Jenkins git plugin, unless the commit sha is incorrect that is provided from the ghprb plugin

@nullify005
Copy link

I usually wouldn't post on a clearly old thread, however I too can't get both PR & push to build using a single ref spec +refs/heads/*:refs/remotes/origin/* +refs/pull/*:refs/remotes/origin/pr/*

In the github hook log I see that the pushed branch doesn't get matched against for some reason
Ignoring refs/heads/master as it doesn't match configured refspecs

I did manage to get it working though, by specifying a refspec of +refs/pull/*:refs/remotes/origin/pr/* for one git repo & then adding a second identical git repo with an empty refspec

With the above it seems that both PR's & branches build properly

@MicahZoltu
Copy link

The steps provided by @nullify005 work for getting the job to trigger, but the job immediately fails on PR builds with

ERROR: Couldn't find any revision to build. Verify the repository and branch configuration for this job.
 > git -c core.askpass=true fetch --tags --progress [email protected]:owner/repo.git +refs/heads/master:refs/remotes/origin/master
 > git rev-parse refs/remotes/origin/pr/2/merge^{commit} # timeout=10
 > git rev-parse refs/remotes/origin/origin/pr/2/merge^{commit} # timeout=10
 > git rev-parse origin/pr/2/merge^{commit} # timeout=10

Notice that it is (as expected) asking for only the master refs but then trying to find the PR refs (which won't exist locally). This is using the Multiple SCM widget in the job configuration.

@MicahZoltu
Copy link

I was able to work around this by specifying both ref specs in both git jobs, but in reverse of each other:

One of them has:

+refs/pull/*:refs/remotes/origin/pr/* +refs/heads/master:refs/remotes/origin/master

The other has:

+refs/heads/master:refs/remotes/origin/master +refs/pull/*:refs/remotes/origin/pr/*

From git's point of view, both are identical (since it doesn't care about order). From the trigger's point of view, they are different because it appears to ignore all but the last.

@MicahZoltu
Copy link

Nevermind, it only works for the PR build when I do that, not the master build. :/

@ssbarnea
Copy link

To be clear, does this means that currently it is impossible to build both master and PR inside the same jenkins job? If not impossible, what would be the correct way to do it?

@MicahZoltu
Copy link

@ssbarnea It is possible, though awkward.

image

I also have triggers setup for Build when a change is pushed to GitHub and GitHub Pull Request Builder. Along with that you will need to have your GitHub webhooks setup, just like you would if you had two separate jobs.

@hmgauthami
Copy link

HI,
I am trying to build a PR from jenkins, Where it works as expected on master branch.
But I am trying to build same PR using different branch "abc".

Kindly please help me how can i configure PR for "abc" branch.

Thanks,
Gauthami

@Puneeth-n
Copy link

@Zoltu This doesn't seem to work.

I have a jenkins job that runs when code is pushed to master and develop branch. This job also picks up PRs. This job also has sha1 as a build parameter to trigger builds manually.

The job picks up PRs and builds them. Same with pushes to master or develop. The issue is when The job is triggered manually. It seems to pickup a random branch. sometimes a PR, sometimes origin/develop.

Job config

build parameters: sha1 (default value: origin/<branchName>)
Branches to build: origin/master
Branches to build: origin/develop
Branches to build: origin/${sha1}
- [√ ]  Build when a change is pushed to GitHub
- [√ ]  GitHub Pull Request Builder

Jenkins and plugin versions

jenkins version: 2.7.1

Git client plugin: 2.0.0    
Git plugin: 3.0.0
GitHub API Plugin: 1.77 
GitHub plugin: 1.21.1
GitHub Pull Request Builder: 1.33.1

alimon pushed a commit to alimon/configs that referenced this issue Nov 20, 2017
A bug in jenkins gitplugin prevents to notice changes when using refspec
over certain branch only [1].

This seems to be fixed in the 3.4.0 version of jenkins gitplugin [2].

[1] janinko/ghprb#77
[2] https://wiki.jenkins.io/display/JENKINS/Git+Plugin

Change-Id: I0d069be886ef0dee8c3fa9108e5a34a7483abdab
Signed-off-by: Aníbal Limón <[email protected]>
@itdependsnetworks
Copy link

itdependsnetworks commented Feb 27, 2018

To save others from mistyping like I did, it is:

+refs/heads/master:refs/remotes/origin/master and
+refs/pull/*:refs/remotes/origin/pr/*

I also had to set branch specifier to ${GITHUB_PR_HEAD_SHA} not ${sha1} and unset Lightweight checkout

Build when a change is pushed to GitHu is now GitHub hook trigger for GITScm polling, and you have to turn Poll SCM on, even if there is no polling be done, and it is a webhook into Jenkins.

@vedrusss
Copy link

vedrusss commented Nov 7, 2018

HI,
I am trying to build a PR from jenkins, Where it works as expected on master branch.
But I am trying to build same PR using different branch "abc".

Kindly please help me how can i configure PR for "abc" branch.

Thanks,
Gauthami

What you must do within section 'Repositories':

  1. specify Repository URL (and credentials if required) - this you have already done;
  2. click onto 'Advanced' and within appeared 'Refspec' field provide command "+refs/heads/branch_abc:refs/remotes/origin/branch_abc" - this will fetch remote branch into jenkins workspace;
  3. within field 'Branch Specifier (blank for 'any')' input command "refs/heads/branch_abc" - this tells jenkins to build the project from branch "branch_abc".

nosmo pushed a commit to nosmo/ghprb-plugin that referenced this issue Dec 12, 2018
Using the default `refspec` prohibits the project from automatically building non-PR branches like `origin/master`. Prepending the `refspec` with the heads and remote/origin allows the project to build pull requests as well as other branches like `origin/my-feature`. This should resolve jenkinsci#77.

Big thanks to janinko#77 (comment) 😄
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.