nemccarthy / stash-pullrequest-builder-plugin

A Jenkins plugin for Building Stash Pull Requests
https://wiki.jenkins-ci.org/display/JENKINS/Stash+pullrequest+builder+plugin
Other
64 stars 130 forks source link

Accessing ${sourceBranch} and ${targetBranch} #40

Closed quiquepaz closed 8 years ago

quiquepaz commented 9 years ago

Hi,

I'm using stath-pullrequest-builder-plugin-1.3.1 on Jenkins-1.624 with git-1.7.12.4 and can't seem to access any of those variables. I have configured a job trying to poll a repo for PRs and build the merge of the source branch with the target branch. Relevant configuration follows:

Source Code Management -> Git -> Repositories:
* Repository URL: https://<user>@<repo>.git 
* Name: origin
* Refspec: +refs/pull-requests/*:refs/remotes/origin/pr/*
* Branches to Build: */${sourceBranch}

Source Code Management -> Additional Behaviours -> Merge Before Build:
* Name of Repository: origin
* Branch to Merge: ${targetBranch}
* Merge Strategy: default
* Fast-forward mode: -ff

When manually triggering the job, I'm getting the following output (note vars like have been manually edited for this post):

Started by user anonymous
[EnvInject] - Loading node environment variables.
Building in workspace /var/lib/jenkins/jobs/<JOB>/workspace
 > git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > git config remote.origin.url https://<REPO># timeout=10
Fetching upstream changes from https://<REPO>
 > git --version # timeout=10
using .gitcredentials to set credentials
 > git config --local credential.helper store --file=/tmp/git5169754694021595086.credentials # timeout=10
Setting http proxy: <PROXY>
 > git -c core.askpass=true fetch --tags --progress https://<REPO> +refs/pull-requests/*:refs/remotes/origin/pr/*
 > git config --local --remove-section credential # timeout=10
Seen branch in repository origin/foo
Seen branch in repository origin/master
Seen branch in repository origin/pr/52/from
Seen branch in repository origin/pr/52/merge
Seen branch in repository origin/release/1.8.10
Seen branch in repository origin/release/1.8.11
Seen branch in repository origin/release/1.8.12
Seen branch in repository origin/release/1.8.13
Seen branch in repository origin/release/1.8.14
Seen branch in repository origin/release/1.8.14.1
Seen branch in repository origin/release/1.8.8
Seen branch in repository origin/release/1.8.9
Seen branch in repository origin/test
Seen 13 remote branches
Merging Revision 754018c35fb9994f5bae371afdbc4069ac46293e (origin/foo, origin/pr/52/from, origin/master) to origin/${targetBranch}, UserMergeOptions{mergeRemote='origin', mergeTarget='${targetBranch}', mergeStrategy='default', fastForwardMode='--ff'}
 > git rev-parse origin/${targetBranch}^{commit} # timeout=10
FATAL: Command "git rev-parse origin/${targetBranch}^{commit}" returned status code 128:
stdout: origin/${targetBranch}^{commit}

stderr: fatal: ambiguous argument 'origin/${targetBranch}^{commit}': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

hudson.plugins.git.GitException: Command "git rev-parse origin/${targetBranch}^{commit}" returned status code 128:
stdout: origin/${targetBranch}^{commit}

stderr: fatal: ambiguous argument 'origin/${targetBranch}^{commit}': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1600)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1576)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1572)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:1233)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:1245)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.revParse(CliGitAPIImpl.java:607)
    at hudson.plugins.git.GitAPI.revParse(GitAPI.java:316)
    at hudson.plugins.git.extensions.impl.PreBuildMerge.decorateRevisionToBuild(PreBuildMerge.java:64)
    at hudson.plugins.git.GitSCM.determineRevisionToBuild(GitSCM.java:955)
    at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1044)
    at hudson.scm.SCM.checkout(SCM.java:485)
    at hudson.model.AbstractProject.checkout(AbstractProject.java:1277)
    at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:610)
    at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:86)
    at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:532)
    at hudson.model.Run.execute(Run.java:1741)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
    at hudson.model.ResourceController.execute(ResourceController.java:98)
    at hudson.model.Executor.run(Executor.java:381)
Finished: FAILURE

If instead I leave empty Branches to Build: and set Branch to Merge: master, my build succeeds. Am I doing something wrong? Can someone help me out here?

quiquepaz commented 9 years ago

ping

SagaciousZed commented 9 years ago

I've also run into this, so you are not alone. Unfortunately, I have not had much time to root cause the problem or to find a work around.

quiquepaz commented 9 years ago

@SagaciousZed I've given up on this plugin. I'm using a custom refspec to ensure the PR branches are pulled and branches like origin/pr/123/merge contain the result of the merge and are updated by Stash when new commits are pushed to an open PR or when the target branch changes and the web fronted requests a diff on PR 123. So I've built around those things.

nemccarthy commented 8 years ago

This should be working fine, please test 1.4 and make sure you have all your config set correctly