How to execute Jenkinsfile with gerrit trigger plugin for changeset in jenkins?
Asked Answered
G

3

7

We use gerrit-trigger in Jenkins, the build is triggered when a new changeset is pushed for review.

Now we want to introduce pipeline and use solution Defining a pipeline in scm

Therefore we expect when the build is triggered, below pipeline plugin can work to checkout this refspec

enter image description here

But the ${GERRIT_REFSPEC} doesn't effect here, it checkouts the master still

 > git rev-parse refs/remotes/origin/master^{commit} # timeout=10
 > git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
Checking out Revision adf5d360582b1b24f088cfa8ac0f0ebf64a57692 (refs/remotes/origin/master)
Commit message: "DO:CI End of summer"
 > git config core.sparsecheckout # timeout=10
 > git checkout -f adf5d360582b1b24f088cfa8ac0f0ebf64a57692

Any suggestion how it can work?

Gesellschaft answered 13/9, 2017 at 18:12 Comment(0)
O
20

I think you need to set:

Repositories > Refspec               = $GERRIT_REFSPEC:$GERRIT_REFSPEC
Branches to build > Branch Specifier = $GERRIT_REFSPEC

Important: do not forget to uncheck the "Lightweight checkout" option.

Ofilia answered 13/9, 2017 at 19:15 Comment(5)
Thx, but no, I got error stderr: fatal: Couldn't find remote ref refs/heads/$GERRIT_REFSPEC, the git plugin here is used under pipeline configuration, the variable is not available.Gesellschaft
I was able to reproduce your issue and added more info.Vacate
Unbelievable !!, it works, can you give me reference why it works?Gesellschaft
The "Lightweight checkout" is a special mode to improve efficiency. Click on the "?" and see that "build parameters will not be substituted into SCM configuration in this mode".Vacate
I didn't quite get that answer until I clicked on that "Advanced" button, which reveal the Refspec field. It works! Thank you.Quack
F
3

Or you can use in Jenkins job.

Refspec: ${GERRIT_REFSPEC}

Branch Specifier: FETCH_HEAD.

Fetich answered 6/12, 2017 at 6:8 Comment(0)
M
-2

uncheck “Lightweight checkout” is enough!! gerrit-trigger plugin should mention this! it wasted my half day!

Mccaffrey answered 1/12, 2017 at 2:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.