How to get the Patchset Number from a Gerrit Event in a Jenkins Pipeline

Retrieving the Patchset Number from a Gerrit Event

clone by http

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
pipeline {
agent any
options { skipDefaultCheckout() }
stages {
stage('Checkout PatchSet') {
steps {
checkout scmGit(
branches: [[name: 'FETCH_HEAD']],
extensions: [
cloneOption(
depth: 1,
shallow: true,
noTags: true,
)
],
userRemoteConfigs: [[
refspec: '${GERRIT_REFSPEC}',
url: 'https://${GERRIT_HOST}/${GERRIT_PROJECT}'
]]
)
}
}
}
}

clone by ssh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
pipeline {
agent any
options { skipDefaultCheckout() }
stages {
stage('Checkout PatchSet') {
steps {
checkout scmGit(
branches: [[name: 'FETCH_HEAD']],
extensions: [
cloneOption(
depth: 1,
shallow: true,
noTags: true,
),
[$class: 'UserIdentity', email: '[email protected]', name: 'Jenkins']
],
userRemoteConfigs: [[
credentialsId: '<CRED_ID>',
refspec: '${GERRIT_REFSPEC}',
url: "ssh://jenkins@${GERRIT_HOST}:${GERRIT_PORT}/${GERRIT_PROJECT}"
]]
)
}
}
}
}