Skip to content

Commit 8fbb6ae

Browse files
committed
Fix and modernize pipeline code
- Use more modern Groovy looping constructs now that they work with new pipeline plugin versions. - Fix the Python bootstrap script to work in case the workspace is empty when the script starts. Change-Id: Ief3bebefd90eb44c6f89264dcb122ddd9b2eefcb
1 parent 9652a69 commit 8fbb6ae

File tree

3 files changed

+10
-19
lines changed

3 files changed

+10
-19
lines changed

workflow/ondemand.groovy

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,9 @@ def setEnvFromActions(overrides)
5555
def doBuild()
5656
{
5757
def builds = actions.builds
58-
def tasks = [:]
5958
def builders = getBuildersMap()
60-
for (int i = 0; i != builds.size(); ++i) {
61-
def bld = builds[i]
62-
tasks[bld.type] = { builders[bld.type](bld) }
59+
def tasks = builds.collectEntries {
60+
[(it.type): { builders[it.type](it) }]
6361
}
6462
parallel tasks
6563
setBuildResult(builds)
@@ -240,8 +238,7 @@ def addSummaryForTriggeredBuilds(builds)
240238
Builds:
241239
<table>
242240
""".stripIndent()
243-
for (int i = 0; i != builds.size(); ++i) {
244-
def bld = builds[i]
241+
for (def bld : builds) {
245242
def summary = bld.status.result
246243
if (bld.summary) {
247244
summary = bld.summary

workflow/release.groovy

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,8 @@ def setTarballEnvironmentVariablesForReleng()
140140

141141
def testTarballs(tarballBuilds, testMatrix)
142142
{
143-
def tasks = [:]
144-
for (int i = 0; i != testMatrix.configs.size(); ++i) {
145-
def config = testMatrix.configs[i]
146-
tasks[config.opts] = {
147-
runSingleTestConfig(tarballBuilds, config)
148-
}
143+
def tasks = testMatrix.configs.collectEntries {
144+
[(it.opts): { runSingleTestConfig(tarballBuilds, it) }]
149145
}
150146
parallel tasks
151147
addConfigurationSummary(testMatrix.configs)
@@ -199,8 +195,7 @@ def addConfigurationSummary(testConfigs)
199195
<td>Result</td>
200196
</tr>
201197
""".stripIndent()
202-
for (int i = 0; i != testConfigs.size(); ++i) {
203-
def config = testConfigs[i]
198+
for (def config : testConfigs) {
204199
def opts = config.opts.join(' ')
205200
text += """\
206201
<tr>

workflow/utils.groovy

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,12 @@ def runRelengScriptInternal(prepareScript, contents, propagate)
9595
except:
9696
pass
9797
os.environ['STATUS_FILE'] = '${statusFile}'
98-
sys.path.append(os.path.abspath('releng'))
9998
""".stripIndent()
10099
if (!propagate) {
101100
script += "os.environ['NO_PROPAGATE_FAILURE'] = '1'\n"
102101
}
103102
script += prepareScript.stripIndent()
103+
script += "sys.path.append(os.path.abspath('releng'))\n"
104104
script += "import releng\n"
105105
script += contents.stripIndent()
106106
try {
@@ -224,8 +224,7 @@ def addBuildRevisionsSummary(revisionList)
224224
Built revisions:
225225
<table>
226226
""".stripIndent()
227-
for (int i = 0; i != revisionList.size(); ++i) {
228-
def rev = revisionList[i]
227+
for (def rev : revisionList) {
229228
text += """\
230229
<tr>
231230
<td>${rev.project}:</td>
@@ -314,8 +313,8 @@ def readSourceVersion()
314313
def setCombinedBuildResult(results)
315314
{
316315
def combinedResult = hudson.model.Result.SUCCESS
317-
for (int i = 0; i != results.size(); ++i) {
318-
def result = hudson.model.Result.fromString(results[i])
316+
for (def resultStr : results) {
317+
def result = hudson.model.Result.fromString(resultStr)
319318
combinedResult = combinedResult.combine(result)
320319
}
321320
currentBuild.setResult(combinedResult.toString())

0 commit comments

Comments
 (0)