Skip to content

Commit 3ec1c0a

Browse files
committed
Extract scoping testcase
1 parent e8c7b86 commit 3ec1c0a

File tree

3 files changed

+41
-23
lines changed

3 files changed

+41
-23
lines changed

src/test/groovy/com/lesfurets/jenkins/unit/declarative/TestDeclarativePipeline.groovy

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,15 +450,22 @@ class TestDeclarativePipeline extends DeclarativePipelineTest {
450450
}
451451

452452
@Test void should_environment() throws Exception {
453-
addEnvVar("labelVar","varWorks")
454453
runScript('Environment_Jenkinsfile')
455454
printCallStack()
456455
assertCallStack().contains('echo(LEVAR1 LE NEW VALUE)')
457-
assertCallStack().contains('echo(LEVAR1 LE NEW VALUE)')
456+
assertCallStack().contains('echo(LEVAR1 LE NEW VALUE without pefixing env)')
458457
assertCallStack().contains('echo(LEVAR2 A COPY OF LE NEW VALUE in build#1)')
459458
assertJobStatusSuccess()
460459
}
461460

461+
@Test void should_be_able_to_access_upper_score_var() throws Exception {
462+
String envVarValue = "envVarValue"
463+
addEnvVar("envVar", envVarValue)
464+
runScript('Scoping_Jenkinsfile')
465+
assertCallStack().contains("echo(Upperscoped string : UpperScope string with envVar: $envVarValue)")
466+
printCallStack()
467+
}
468+
462469
@Test void not_running_stage_after_failure() throws Exception {
463470
runScript('StageFailed_Jenkinsfile')
464471
printCallStack()
Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,19 @@
1-
def call() {
2-
String label = "SomePrefix-${labelVar}"
3-
4-
pipeline {
5-
agent label
6-
environment {
7-
LEVAR1 = "LE VALUE 1"
8-
}
9-
stages {
10-
stage('Example') {
11-
environment {
12-
LEVAR1 = "LE NEW VALUE"
13-
LEVAR2 = "A COPY OF ${env.LEVAR1} in build#${currentBuild.number}"
14-
}
15-
steps {
16-
echo "LEVAR1 ${env.LEVAR1}"
17-
echo "LEVAR2 ${env.LEVAR2}"
18-
}
1+
pipeline {
2+
agent any
3+
environment {
4+
LEVAR1 = "LE VALUE 1"
5+
}
6+
stages {
7+
stage('Example') {
8+
environment {
9+
LEVAR1 = "LE NEW VALUE"
10+
LEVAR2 = "A COPY OF ${env.LEVAR1} in build#${currentBuild.number}"
11+
}
12+
steps {
13+
echo "LEVAR1 ${LEVAR1}"
14+
echo "LEVAR1 ${LEVAR1} without pefixing env"
15+
echo "LEVAR2 ${env.LEVAR2}"
1916
}
2017
}
2118
}
22-
}
23-
24-
call()
19+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
def call() {
2+
String upperscopeSTring = "UpperScope string with envVar: ${envVar}"
3+
4+
pipeline {
5+
agent upperscopeSTring
6+
stages {
7+
stage('Echo stage') {
8+
steps {
9+
echo "Upperscoped string : $upperscopeSTring"
10+
}
11+
}
12+
}
13+
}
14+
}
15+
16+
call()

0 commit comments

Comments
 (0)