Closed lavaman closed 9 years ago
+1
same here. we heavily use forks and PR builds from from into feature branch of a project is failing due to not found paths
Hmmm... The plugin does work with forks, I have tried with a local fork in my Stash user directory, branch names are the same. Could you provide more details of the PR that its failing with?
After testing again this works fine. For example, from a fork in my user repo, nathanm, branch feature/test-pr to NormalRemote/master and it works fine. Are you sure this isnt a permissions problem? Make sure your jenkins git user has permission to access your fork. If not add the user or make it public.
Please make sure you are using the latest version as well from the Jenkins plugin site.
In the console output of all my requests, I see that it finds there is a PR, but it only ever attempts to checkout the last commit in upstream. I never see any attempt to check out the SHA of the commit in the PR. The Jenkins user has read access on the upstream and my fork. I don't see any Stash access errors in the Jenkins log. FYI, this is an internally hosted instance of Stash, not the service. I'm using the latest version of Jenkins (1.614) and the latest version of the plugin (1.0.1)
Hmmm, this is not the behaviour I see. Can you provide your git log? Sounds like you have something missing in your git plugin setup...
Cloning the remote Git repository
Cloning repository ssh://git@git.int.stashsvr.coy.com:7999/~nem/my-project.git
> git init /home/jenkins/workspace/workspace/workspace/Personalization/my-project-pr-build # timeout=10
Fetching upstream changes from ssh://git@git.int.stashsvr.coy.com:7999/~nem/my-project.git
> git --version # timeout=10
using GIT_SSH to set credentials
> git -c core.askpass=true fetch --tags --progress ssh://git@git.int.stashsvr.coy.com:7999/~nem/my-project.git +refs/heads/*:refs/remotes/origin/*
> git config remote.origin.url ssh://git@git.int.stashsvr.coy.com:7999/~nem/my-project.git # timeout=10
> git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/* # timeout=10
> git config remote.origin.url ssh://git@git.int.stashsvr.coy.com:7999/~nem/my-project.git # timeout=10
Fetching upstream changes from ssh://git@git.int.stashsvr.coy.com:7999/~nem/my-project.git
using GIT_SSH to set credentials
> git -c core.askpass=true fetch --tags --progress ssh://git@git.int.stashsvr.coy.com:7999/~nem/my-project.git +refs/heads/*:refs/remotes/origin/*
> git rev-parse refs/remotes/origin/feature/test-pr-2^{commit} # timeout=10
> git rev-parse refs/remotes/origin/origin/feature/test-pr-2^{commit} # timeout=10
Merging Revision 7aa722d6e0df1828cebe7b4c91d0efcafd1e3460 (refs/remotes/origin/feature/test-pr-2) to origin/master, UserMergeOptions{mergeRemote='origin', mergeTarget='${targetBranch}', mergeStrategy='default', fastForwardMode='--ff'}
> git rev-parse origin/master^{commit} # timeout=10
> git config core.sparsecheckout # timeout=10
> git checkout -f origin/master
> git merge --ff 7aa722d6e0df1828cebe7b4c91d0efcafd1e3460 # timeout=10
> git rev-parse HEAD^{commit} # timeout=10
Seen 18 remote branches
Checking out Revision 7c9c8b0f4da8b7bb94129cf122839a77bb8689a7 (origin/master)
> git config core.sparsecheckout # timeout=10
> git checkout -f 7c9c8b0f4da8b7bb94129cf122839a77bb8689a7
> git rev-list 5164affa1ed5b9e0b993413b5ae3e102cdfb81cb # timeout=10
First time build. Skipping changelog.
Notified Stash for commit with id 7aa722d6e0df1828cebe7b4c91d0efcafd1e3460
Notified Stash for commit with id 7c9c8b0f4da8b7bb94129cf122839a77bb8689a7
PR #1 fixing tests Building in workspace /var/lib/jenkins/jobs/hpsa/workspace
git rev-parse --is-inside-work-tree # timeout=10 Fetching changes from the remote Git repository git config remote.origin.url ssh://git@git.foo.com:7999/cpm/hpsa.git # timeout=10 Fetching upstream changes from ssh://git@git.foo.com:7999/cpm/hpsa.git git --version # timeout=10 using GITSSH to set credentials git fetch --tags --progress ssh://git@git.foo.com:7999/cpm/hpsa.git +refs/heads/:refs/remotes/origin/_ git rev-parse refs/remotes/origin/master^{commit} # timeout=10 git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10 Checking out Revision d099c8fe0b273e0c92cdbd1a0b13da43cd98bac8 (refs/remotes/origin/master) git config core.sparsecheckout # timeout=10 git checkout -f d099c8fe0b273e0c92cdbd1a0b13da43cd98bac8 git rev-list d099c8fe0b273e0c92cdbd1a0b13da43cd98bac8 # timeout=10
Do I need additional behaviors? Clean before/after or something?
I think I may know what it is. You appear to have a separate job just for testing PRs. I added this to the job that checks the git repo for any change. Does this need to be it's own job?
Yeah we need two jobs, one for PRs and one for master. Try clearing the workspace before the build as a pre-build step. Delete workspace before build starts
Your git config should look like this;
So the delete workspace part seemed to be necessary. I also had added the jenkins user's ssh key to the project, and not to its user in stash, which prevented it from accessing my fork. This is now working fine for me.
Thanks for the help.
This appears to only work if the PR is from a branch in the same repository. Would it be possible to make this work with PRs from forks as well? I'm not much of a Java dev, but I'd be willing to take a stab at it if you can point me in the right direction.
Thanks