Skip to content

Commit 2562886

Browse files
authored
ci(jenkins): the environment GIT_BASE_COMMIT is not accessible (#569)
1 parent f99a65b commit 2562886

File tree

2 files changed

+46
-28
lines changed

2 files changed

+46
-28
lines changed

.ci/Jenkinsfile

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
@Library('apm@current') _
33

44
import co.elastic.matrix.*
5+
import groovy.transform.Field
6+
7+
/**
8+
This is the git commit sha which it's required to be used in different stages.
9+
It does store the env GIT_SHA
10+
*/
11+
@Field def gitCommit
512

613
pipeline {
714
agent none
@@ -42,6 +49,9 @@ pipeline {
4249
deleteDir()
4350
gitCheckout(basedir: "${BASE_DIR}")
4451
stash allowEmpty: true, name: 'source', useDefaultExcludes: false
52+
script {
53+
gitCommit = env.GIT_SHA
54+
}
4555
}
4656
}
4757
stage('Sanity checks') {
@@ -60,36 +70,35 @@ pipeline {
6070
docker.image('python:3.7-stretch').inside("-e PATH=${PATH}:${env.WORKSPACE}/bin"){
6171
dir("${BASE_DIR}"){
6272
// registry: '' will help to disable the docker login
63-
preCommit(commit: "${GIT_BASE_COMMIT}", junit: true, registry: '')
73+
preCommit(commit: "${gitCommit}", junit: true, registry: '')
6474
}
6575
}
6676
}
6777
}
6878
}
6979
}
70-
}
71-
}
72-
/**
73-
Execute unit tests.
74-
*/
75-
stage('Test') {
76-
agent { label 'linux && immutable' }
77-
options {
78-
timeout(time: 1, unit: 'HOURS')
79-
skipDefaultCheckout()
80-
}
81-
steps {
82-
withGithubNotify(context: 'Test', tab: 'tests') {
83-
deleteDir()
84-
unstash "source"
85-
dir("${BASE_DIR}"){
86-
script {
87-
def node = readYaml(file: '.ci/.jenkins_python.yml')
88-
def parallelTasks = [:]
89-
node['PYTHON_VERSION'].each{ version ->
90-
parallelTasks["${version}"] = generateStep(version)
91-
}
92-
parallel(parallelTasks)
80+
/**
81+
Execute unit tests.
82+
*/
83+
stage('Test') {
84+
options {
85+
timeout(time: 1, unit: 'HOURS')
86+
skipDefaultCheckout()
87+
}
88+
steps {
89+
withGithubNotify(context: 'Test', tab: 'tests') {
90+
deleteDir()
91+
unstash "source"
92+
dir("${BASE_DIR}"){
93+
script {
94+
def node = readYaml(file: '.ci/.jenkins_python.yml')
95+
def parallelTasks = [:]
96+
node['PYTHON_VERSION'].each{ version ->
97+
parallelTasks["${version}"] = generateStep(version)
98+
}
99+
parallel(parallelTasks)
100+
}
101+
}
93102
}
94103
}
95104
}
@@ -177,7 +186,7 @@ def generateStep(version){
177186
build(job: "apm-agent-python/apm-agent-python-downstream/${branch}",
178187
parameters: [
179188
string(name: 'PYTHON_VERSION', value: version),
180-
string(name: 'BRANCH_SPECIFIER', value: env.GIT_BASE_COMMIT),
189+
string(name: 'BRANCH_SPECIFIER', value: gitCommit),
181190
string(name: 'MERGE_TARGET', value: branch),
182191
],
183192
propagate: true,

Jenkinsfile

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ it is need as field to store the results of the tests.
1010
*/
1111
@Field def pythonTasksGen
1212

13+
/**
14+
This is the git commit sha which it's required to be used in different stages.
15+
It does store the env GIT_SHA
16+
*/
17+
@Field def gitCommit
18+
1319
pipeline {
1420
agent none
1521
environment {
@@ -56,6 +62,9 @@ pipeline {
5662
deleteDir()
5763
gitCheckout(basedir: "${BASE_DIR}", githubNotifyFirstTimeContributor: true)
5864
stash allowEmpty: true, name: 'source', useDefaultExcludes: false
65+
script {
66+
gitCommit = env.GIT_SHA
67+
}
5968
}
6069
}
6170
stage('Sanity checks') {
@@ -74,7 +83,7 @@ pipeline {
7483
docker.image('python:3.7-stretch').inside("-e PATH=${PATH}:${env.WORKSPACE}/bin"){
7584
dir("${BASE_DIR}"){
7685
// registry: '' will help to disable the docker login
77-
preCommit(commit: "${GIT_BASE_COMMIT}", junit: true, registry: '')
86+
preCommit(commit: "${gitCommit}", junit: true, registry: '')
7887
}
7988
}
8089
}
@@ -147,10 +156,10 @@ pipeline {
147156
log(level: 'INFO', text: 'Launching Async ITs')
148157
build(job: env.ITS_PIPELINE, propagate: false, wait: false,
149158
parameters: [string(name: 'AGENT_INTEGRATION_TEST', value: 'Python'),
150-
string(name: 'BUILD_OPTS', value: "--with-agent-python-flask --python-agent-package git+https://github.com/${env.CHANGE_FORK?.trim() ?: 'elastic' }/${env.REPO}.git@${env.GIT_BASE_COMMIT}"),
159+
string(name: 'BUILD_OPTS', value: "--with-agent-python-flask --python-agent-package git+https://github.com/${env.CHANGE_FORK?.trim() ?: 'elastic' }/${env.REPO}.git@${gitCommit}"),
151160
string(name: 'GITHUB_CHECK_NAME', value: env.GITHUB_CHECK_ITS_NAME),
152161
string(name: 'GITHUB_CHECK_REPO', value: env.REPO),
153-
string(name: 'GITHUB_CHECK_SHA1', value: env.GIT_BASE_COMMIT)])
162+
string(name: 'GITHUB_CHECK_SHA1', value: gitCommit)])
154163
githubNotify(context: "${env.GITHUB_CHECK_ITS_NAME}", description: "${env.GITHUB_CHECK_ITS_NAME} ...", status: 'PENDING', targetUrl: "${env.JENKINS_URL}search/?q=${env.ITS_PIPELINE.replaceAll('/','+')}")
155164
}
156165
}

0 commit comments

Comments
 (0)