Gerrit trigger for Jenkins couldn't find any revision to build
Asked Answered
A

6

17

I have trouble using Jenkins+Gerrit.

Here is what I got so far:

Here is my issue. When building (gerrit triggered or manually), log output is:

 > git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > git config remote.origin.url ssh://user@host:29418/testproject # timeout=10
Fetching upstream changes from ssh://user@host:29418/testproject
 > git --version # timeout=10
using GIT_SSH to set credentials 
 > git -c core.askpass=true fetch --tags --progress ssh://user@host:29418/testproject refs/heads/master
 > git rev-parse origin/$GERRIT_BRANCH^{commit} # timeout=10
 > git rev-parse $GERRIT_BRANCH^{commit} # timeout=10
ERROR: Couldn't find any revision to build. Verify the repository and branch configuration for this job.
Finished: FAILURE

I am stuck with this message, tried with empty repo, non-empty ones, and also with or without changeset "in review"

Analcite answered 13/3, 2015 at 14:2 Comment(1)
I'm having the same problem (same config as you describe above) ... the build works fine if I trigger is manually, and fails is it is launched by the Gerrit Trigger. Have you found a solution to this problem ?Epicarp
E
15

I used to have this problem and I think I have now fixed it, I am blaming the Jenkins UI for hiding some essential configuration elements ;)

Here is the output of my Jenkins build prior to the fix:

Triggered by Gerrit: https://bbpcode.epfl.ch/code/15056
[EnvInject] - Loading node environment variables.
Building remotely on rh6.6-02 (amd64-RedHatEnterpriseServer 6.6 RedHatEnterpriseServer amd64-RedHatEnterpriseServer-6.6 rh6.x RedHatEnterpriseServer-6.6 amd64) in workspace /var/tmp/jenkins/workspace/datamining.nip-commons.gerrit
 > /usr/bin/git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > /usr/bin/git config remote.origin.url ssh://bbpcode.epfl.ch/datamining/nip-commons # timeout=10
Fetching upstream changes from ssh://bbpcode.epfl.ch/datamining/nip-commons
 > /usr/bin/git --version # timeout=10
 > /usr/bin/git fetch --tags --progress ssh://bbpcode.epfl.ch/datamining/nip-commons +refs/heads/*:refs/remotes/origin/*
 > /usr/bin/git rev-parse 74e4ff18f54bd6e046f7af016614193f566adfe4^{commit} # timeout=10
ERROR: Couldn't find any revision to build. Verify the repository and branch configuration for this job.
Started calculate disk usage of build
Finished Calculation of disk usage of build in 0 seconds
Started calculate disk usage of workspace
Finished Calculation of disk usage of workspace in 0 seconds
Finished: FAILURE

SOLUTION

You will need to open your build configuration and go to the section 'Source Code Management' as shown below:

Git config with Advanced button

Now you will notice that there is a button 'Advanced', click it to reveal the extra fields as below:

Git config with refspec field revealed

Now you can type your refspec here: $GERRIT_REFSPEC

Now either retrigger a failed build or abandon reviews and submit a new one and it should be working.

Here is the output of the Jenkins job now that we have the appropriate refspec:

Retriggered by user kerrien for Gerrit: https://bbpcode.epfl.ch/code/15056
[EnvInject] - Loading node environment variables.
Building remotely on rh6.6-02 (amd64-RedHatEnterpriseServer 6.6 RedHatEnterpriseServer amd64-RedHatEnterpriseServer-6.6 rh6.x RedHatEnterpriseServer-6.6 amd64) in workspace /var/tmp/jenkins/workspace/datamining.nip-commons.gerrit
 > /usr/bin/git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > /usr/bin/git config remote.origin.url ssh://bbpcode.epfl.ch/datamining/nip-commons # timeout=10
Fetching upstream changes from ssh://bbpcode.epfl.ch/datamining/nip-commons
 > /usr/bin/git --version # timeout=10
 > /usr/bin/git fetch --tags --progress ssh://bbpcode.epfl.ch/datamining/nip-commons refs/changes/56/15056/2
 > /usr/bin/git rev-parse 74e4ff18f54bd6e046f7af016614193f566adfe4^{commit} # timeout=10
Checking out Revision 74e4ff18f54bd6e046f7af016614193f566adfe4 (dev)
 > /usr/bin/git config core.sparsecheckout # timeout=10
 > /usr/bin/git checkout -f 74e4ff18f54bd6e046f7af016614193f566adfe4
 > /usr/bin/git rev-parse FETCH_HEAD^{commit} # timeout=10
 > /usr/bin/git rev-list 2649d51369413cef4dfb7ec50939945005514cfa # timeout=10
Cleaning workspace
 > /usr/bin/git rev-parse --verify HEAD # timeout=10
Resetting working tree
 > /usr/bin/git reset --hard # timeout=10
 > /usr/bin/git clean -fdx # timeout=10
Triggering datamining.nip-commons.gerrit » default
datamining.nip-commons.gerrit » default completed with result SUCCESS
Started calculate disk usage of build
Finished Calculation of disk usage of build in  2 second
Started calculate disk usage of workspace
Finished Calculation of disk usage of workspace in 0 seconds
Finished: SUCCESS
Epicarp answered 30/7, 2015 at 7:28 Comment(1)
Add $GERRIT_REFSPEC in Advanced->Refspec worked for me! Thanks. BTW, after adding $GERRIT_REFSPEC, start build manually will cause the error "couldn't find remote ref $GERRIT_REFSPEC". But it will run perfectly triggered by Gerrit.Boswall
F
5
  1. Leave the 'Branches to build > Branch specifier' field blank
  2. Click the Advanced button, and set a custom refspec: +refs/heads/feature/my-feature:refs/remotes/origin/feature/my-feature With these settings, the plugin will correctly perform a fetch and then check out only the 'feature/my-feature' branch.
Flew answered 16/4, 2015 at 11:57 Comment(1)
Same error ! ERROR: Couldn't find any revision to build. Verify the repository and branch configuration for this job. Finished: FAILUREAnalcite
S
1

You could try to configure like that

  • Refspec = refs/changes/:refs/changes/
  • Branches to build = $GERRIT_REFSPEC

Follow the full configuration there

If you click "Build Now", Jenkins won't be able to get sources since $GERRIT_REFSPEC doesn't exist on that case.

Spectroheliograph answered 31/8, 2016 at 6:49 Comment(0)
I
0

Replace $GERRIT_BRANCH with $GERRIT_REFSPEC

Immutable answered 16/3, 2015 at 1:2 Comment(3)
I still have the same error > git -c core.askpass=true fetch --tags --progress ssh://user@host:29418/testproject refs/heads/master > git rev-parse refs/remotes/origin/master^{commit} # timeout=10 > git rev-parse refs/remotes/origin/refs/heads/master^{commit} # timeout=10 > git rev-parse refs/heads/master^{commit} # timeout=10 ERROR: Couldn't find any revision to build. Verify the repository and branch configuration for this job. Finished: FAILUREAnalcite
I hope you are not hitting the Build Now?Immutable
Nop, it's linked to Gerrit new changeset. And the trigger works fine.Analcite
T
0

After lot's of struggle and keeping eye on log,finally I got the solution.

It's just configuration mistake that we all did. Once checked check box This project is parameterized Below configuration need to be done

enter image description here

Here I named parameter name as branchgit Now in Source Code Management we need to concentrate on Branches to build whose value should be only "$branchgit" as per below image enter image description here

Taught answered 9/1, 2017 at 15:20 Comment(0)
L
0

The following settings worked for me: Fill Refspec with $GERRIT_REFSPEC in "Advanced" section. "Branch Specifier" can be blank or any valid value

Laylalayman answered 19/3, 2019 at 5:45 Comment(1)
Sorry! this value will cause manual build fail(immediate build). +refs/heads/*:refs/remotes/origin/* this value can work on both modeLaylalayman

© 2022 - 2024 — McMap. All rights reserved.