I am writing because there is something not clear to me on how to configure jenkins to fetch from gerrit the changes for building my project.
There is a lot of tutorial / examples on the net related to how to connect all those piece of code.
But I didn't found any that explain what I want to do.
I think it's possible but... well. I'm not sure.
I have a repo manifest that contains a lot of different modules of the final application. The app was written in this way because I can change a module and substitute it with another with similar code that do a different job. For example they can be personalization for different customers.
I setup a job in jenkins that catch every commit in each submodule.
I connected Jenkins to Gerrit and I can start the build with gerrit trigger.
It works and I can build my master and the current master.
My problem is that when I send a patch for review jenkins build the master, not the patch I sent. I would like to test the last patch before integrating it on master.
Modules cannot be built standalone because they are all connected in some way so I cannot check each part alone.
Someone was able to accomplish something like this?
When the Gerrit Trigger start the Jenkins job, you could execute the following to prepare the workspace before you execute the build:
Use the GERRIT_PROJECT and GERRIT_REFSPEC Gerrit Trigger env variables and execute the following commands to checkout the patchset of the changed repository:
git fetch https://USER@SERVER/a/$GERRIT_PROJECT $GERRIT_REFSPEC && git checkout FETCH_HEAD
git fetch ssh://USER@SERVER:29418/$GERRIT_PROJECT $GERRIT_REFSPEC && git checkout FETCH_HEAD
The key is to set accordingly the "Repositories" > "Advanced.." > "Refspec" and the "Branches to build" > "Branch Specifier" fields in: Job > Configure > Source Code Management > Git
If you want to build the "master" branch then set:
Refspec = +refs/heads/master:refs/remotes/origin/master Branch Specifier = refs/heads/master
If you want to build the patchset then set:
Refspec = $GERRIT_REFSPEC:$GERRIT_REFSPEC Branch Specifieer = $GERRIT_REFSPEC
Click on the "?" at the right of the field to see more details.