Skip to content

Commit fa41f0a

Browse files
authored
[sonic-utilities] Enclose conditional statements in a 'script' block (sonic-net#189)
It appears that in declarative pipelines, conditional statements must be enclosed within `script` blocks, otherwise we will see errors like the following: ``` 14:10:20 org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: 14:10:20 WorkflowScript: 14: Expected a step @ line 14, column 17. 14:10:20 if ('${ghprbTargetBranch}' == '201911') { 14:10:20 ^ ```
1 parent c7a8ec3 commit fa41f0a

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

jenkins/common/sonic-utilities-build-pr/Jenkinsfile

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,28 @@ pipeline {
1111
refspec: '+refs/pull/*:refs/remotes/origin/pr/*']]])
1212
}
1313

14-
if ('${ghprbTargetBranch}' == '201911') {
15-
copyArtifacts(projectName: 'vs/buildimage-vs-201911', filter: '**/*', target: 'buildimage', flatten: false)
16-
} else {
17-
copyArtifacts(projectName: 'common/sonic-swss-common-build', filter: '**/*.deb', target: 'swss-common', flatten: true)
18-
copyArtifacts(projectName: 'vs/sonic-swss-build', filter: '**/*.deb', target: 'swss', flatten: true)
19-
copyArtifacts(projectName: 'vs/sonic-sairedis-build', filter: '**/*.deb', target: 'sairedis', flatten: true)
20-
copyArtifacts(projectName: 'vs/buildimage-vs-all', filter: '**/*', target: 'buildimage', flatten: false)
14+
script {
15+
if ('${ghprbTargetBranch}' == '201911') {
16+
copyArtifacts(projectName: 'vs/buildimage-vs-201911', filter: '**/*', target: 'buildimage', flatten: false)
17+
} else {
18+
copyArtifacts(projectName: 'common/sonic-swss-common-build', filter: '**/*.deb', target: 'swss-common', flatten: true)
19+
copyArtifacts(projectName: 'vs/sonic-swss-build', filter: '**/*.deb', target: 'swss', flatten: true)
20+
copyArtifacts(projectName: 'vs/sonic-sairedis-build', filter: '**/*.deb', target: 'sairedis', flatten: true)
21+
copyArtifacts(projectName: 'vs/buildimage-vs-all', filter: '**/*', target: 'buildimage', flatten: false)
22+
}
2123
}
2224
}
2325
}
2426

2527
stage('Build') {
2628
steps {
2729
withCredentials([usernamePassword(credentialsId: 'sonicdev-cr', usernameVariable: 'REGISTRY_USERNAME', passwordVariable: 'REGISTRY_PASSWD')]) {
28-
if ('${ghprbTargetBranch}' == '201911') {
29-
sh './scripts/common/sonic-utilities-build/build_201911.sh'
30-
} else {
31-
sh './scripts/common/sonic-utilities-build/build.sh'
30+
script {
31+
if ('${ghprbTargetBranch}' == '201911') {
32+
sh './scripts/common/sonic-utilities-build/build_201911.sh'
33+
} else {
34+
sh './scripts/common/sonic-utilities-build/build.sh'
35+
}
3236
}
3337
}
3438
}
@@ -45,9 +49,11 @@ pipeline {
4549
stage('Test') {
4650
steps {
4751
wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'xterm']) {
48-
/* We will only run SwSS tests against master branch PRs */
49-
if ('${ghprbTargetBranch}' == 'master') {
50-
sh './scripts/common/sonic-utilities-build/test.sh'
52+
script {
53+
/* We will only run SwSS tests against master branch PRs */
54+
if ('${ghprbTargetBranch}' == 'master') {
55+
sh './scripts/common/sonic-utilities-build/test.sh'
56+
}
5157
}
5258
}
5359
}

0 commit comments

Comments
 (0)