In a Jenkins / git / Gerrit setup I currently maintain a bunch of "pipeline-scm" jobs: e.g. one of them gets triggered by Gerrit on an incoming change request in order to validate this change.
There is a "Gerrit Trigger" plugin for Jenkins that provides that provides job with a git refspec and the branch that change relates to - among lots of other details.
When you setup a "Pipeline script from SCM" a job instance (build) will be provided with an scm object which can be used to checkout the change and also gets used by Jenkins itself to show some meta information on the build's overview, e.g. the commits that define this change:
Now here comes my problem:
For [..] reasons I need to turn this "Pipeline script from SCM" job into a "Pipeline script" job. I.e. instead of just using the auto-generated scm object (which is being used on the master node already to fetch the pipeline script (and most likely to utilize the meta information about this change)) to run checkout scm in my pipeline script I now have to create this object manually:
scm = [
$class: "GitSCM",
userRemoteConfigs: [[
credentialsId: <SOME ID>,
url: <REPO-URL>,
]],
branches: [[
name: <BRANCH-NAME>,
]],
]
checkout scm
This raises two questions:
I know the Gerrit plugin provides details about a change in environment variables like
GERRIT_PATCHSET_REVISION,GERRIT_REFSPECandGERRIT_BRANCH- but how do I use them? I've seen examples which definebranchesusingGERRIT_BRANCH, others useGERRIT_PATCHSET_REVISIONothers use a branch pattern like*/master.how does the meta information which can be extracted from a valid
scminstance get to the build's overview page? I guess thepipeline-scmmechanism makes the master node populate this page automatically, but now the master node has noscmobject in advance anymore. Is there a mechanism like "currentBuild.updateMetaInfo(scm)`?
Is there any documentation about how to properly set up and use a scm object (as Jenkins does) in a standalone pipeline job (i.e. without the scm mechanism)?
Update:
This scm configuration works for me in terms of checkout:
scm = [
$class: "GitSCM",
userRemoteConfigs: [[
credentialsId: <MY_ID>,
url: <MY_REPO_URL>,
refspec: env["GERRIT_REFSPEC],
]],
branches: [[name: "FETCH_HEAD"]],
];
Unfortunately even after checkout scm no "Changes" show up, instead the overview page only displays this:
The build matrix in the job overview also states there are no changes:


