Skip to content

Commit a488fef

Browse files
committed
fix(jjb): escape Groovy DSL braces to avoid JJB parsing errors
Escaped all { and } in the embedded Groovy pipeline DSL using double braces ({{, }}) to prevent Jenkins Job Builder (JJB) from misinterpreting them as Python format placeholders. This resolves the unexpected '{' in field name error when running jenkins-jobs test or update. Also moved the groovy script to the script folder for better readability Signed-off-by: Manimaran M <manim@redhat.com>
1 parent e37994d commit a488fef

File tree

2 files changed

+62
-62
lines changed

2 files changed

+62
-62
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
pipeline {{
2+
agent {{ label 'cico-workspace' }}
3+
4+
stages {{
5+
stage('Trigger FSAL Jobs in Parallel') {{
6+
steps {{
7+
script {{
8+
def gerritParams = [
9+
'GERRIT_PATCHSET_REVISION', 'GERRIT_REFSPEC', 'GERRIT_PROJECT', 'GERRIT_HOST'
10+
]
11+
12+
def sharedParams = gerritParams.collect {{ paramName ->
13+
string(name: paramName, value: env.getProperty(paramName) ?: '')
14+
}}
15+
16+
def jobList = ['fsal-cephfs', 'fsal-vfs', 'fsal-gpfs', 'fsal-rgw']
17+
def results = [:]
18+
def messages = ["**FSAL Job Results:**\\n"]
19+
20+
parallel jobList.collectEntries {{ job ->
21+
[(job): {{
22+
def build = build job: job, parameters: sharedParams, propagate: false, wait: true
23+
results[job] = build
24+
25+
def msg = ''
26+
try {{
27+
def jobUrl = build.absoluteUrl
28+
def artifactUrl = "${{jobUrl}}artifact/result_message.txt"
29+
sh "curl -s -o tmp_result_message_${{job}}.txt '${{artifactUrl}}'"
30+
msg = readFile("tmp_result_message_${{job}}.txt").trim()
31+
}} catch (Exception e) {{
32+
msg = "**🔴 ${{job}}: ERROR fetching result_message.txt**"
33+
}}
34+
35+
messages << msg
36+
}}]
37+
}}
38+
39+
def finalMessage = messages.join("\\n")
40+
writeFile file: 'gerrit_message.txt', text: finalMessage
41+
42+
def notifyFlag = '--notify NONE'
43+
if (finalMessage.contains('FAILED')) {{
44+
notifyFlag = '--notify ALL'
45+
}}
46+
47+
withCredentials([file(credentialsId: 'GERRITHUB_PRIVATE_KEY', variable: 'GERRITHUB_KEY_FILE')]) {{
48+
sh """
49+
ssh -i $GERRITHUB_KEY_FILE -l jenkins-glusterorg -o StrictHostKeyChecking=no -p 29418 $GERRIT_HOST \\
50+
gerrit review \\
51+
$notifyFlag \\
52+
--message "'$(cat gerrit_message.txt)'" \\
53+
--project $GERRIT_PROJECT \\
54+
$GERRIT_PATCHSET_REVISION
55+
"""
56+
}}
57+
}}
58+
}}
59+
}}
60+
}}
61+
}}

jobs/trigger-fsal-on-new-patch.yml

Lines changed: 1 addition & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -38,65 +38,4 @@
3838
branches:
3939
- branch-pattern: "**"
4040
branch-compare-type: ANT
41-
dsl: |
42-
pipeline {
43-
agent { label 'cico-workspace' }
44-
45-
stages {
46-
stage('Trigger FSAL Jobs in Parallel') {
47-
steps {
48-
script {
49-
def gerritParams = [
50-
'GERRIT_PATCHSET_REVISION', 'GERRIT_REFSPEC', 'GERRIT_PROJECT','GERRIT_HOST'
51-
]
52-
53-
def sharedParams = gerritParams.collect { paramName ->
54-
string(name: paramName, value: env.getProperty(paramName) ?: '')
55-
}
56-
57-
def jobList = ['fsal-cephfs', 'fsal-vfs', 'fsal-gpfs', 'fsal-rgw']
58-
def results = [:]
59-
def messages = ["**FSAL Job Results:**\\n"]
60-
61-
parallel jobList.collectEntries { job ->
62-
[(job): {
63-
def build = build job: job, parameters: sharedParams, propagate: false, wait: true
64-
results[job] = build
65-
66-
def msg = ''
67-
try {
68-
def jobUrl = build.absoluteUrl
69-
def artifactUrl = "\${jobUrl}artifact/result_message.txt"
70-
sh "curl -s -o tmp_result_message_\${job}.txt '\${artifactUrl}'"
71-
msg = readFile("tmp_result_message_\${job}.txt").trim()
72-
} catch (Exception e) {
73-
msg = "**🔴 \${job}: ERROR fetching result_message.txt**"
74-
}
75-
76-
messages << msg
77-
}]
78-
}
79-
80-
def finalMessage = messages.join("\\n")
81-
writeFile file: 'gerrit_message.txt', text: finalMessage
82-
83-
def notifyFlag = '--notify NONE' // default
84-
if (finalMessage.contains('FAILED')) {
85-
notifyFlag = '--notify ALL'
86-
}
87-
88-
withCredentials([file(credentialsId: 'GERRITHUB_PRIVATE_KEY', variable: 'GERRITHUB_KEY_FILE')]) {
89-
sh """
90-
ssh -i \$GERRITHUB_KEY_FILE -l jenkins-glusterorg -o StrictHostKeyChecking=no -p 29418 \$GERRIT_HOST \\
91-
gerrit review \\
92-
$notifyFlag \\
93-
--message "'$(cat gerrit_message.txt)'" \\
94-
--project $GERRIT_PROJECT \\
95-
$GERRIT_PATCHSET_REVISION
96-
'''
97-
}
98-
}
99-
}
100-
}
101-
}
102-
}
41+
dsl: !include-raw: scripts/trigger-fsal-on-new-patch.groovy

0 commit comments

Comments
 (0)