Skip to content

Commit 12e7dcb

Browse files
lemeurhervetimja
andauthored
chore(pipeline): use infra.getBuildAgentLabel in agentSelector (#1137)
* chore(pipeline): use `infra.getBuildAgentLabel` in `agentSelector` * remove TODO comments linking to helpdesk issues * test jenkins-infra/pipeline-library#985 * not a test anymore * Apply suggestions from code review Co-authored-by: Tim Jacomb <21194782+timja@users.noreply.github.com> --------- Co-authored-by: Tim Jacomb <21194782+timja@users.noreply.github.com>
1 parent c258456 commit 12e7dcb

File tree

1 file changed

+28
-29
lines changed

1 file changed

+28
-29
lines changed

Jenkinsfile

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,38 +6,37 @@ properties([
66
pipelineTriggers([cron(cronExpr)]),
77
])
88

9-
def agentSelector(String imageType) {
10-
// Linux agent
11-
if (imageType == 'linux') {
12-
// This function is defined in the jenkins-infra/pipeline-library
13-
if (infra.isTrusted()) {
14-
return 'linux'
15-
} else {
16-
// Need Docker and a LOT of memory for faster builds (due to multi archs) or fallback to linux (trusted.ci)
17-
return 'docker-highmem'
18-
}
19-
}
20-
// Windows Server Core 2022 agent
21-
if (imageType.contains('2022')) {
22-
return 'windows-2022'
23-
}
24-
// Windows Server Core 2019 agent (for nanoserver 1809 & ltsc2019 and for windowservercore ltsc2019)
25-
return 'windows-2019'
26-
}
9+
def agentSelector(String imageType, retryCounter) {
10+
def platform
11+
switch (imageType) {
12+
// nanoserver-1809, nanoserver-ltsc2019 and windowservercore-ltsc2019
13+
case ~/.*(1809|2019)/:
14+
platform = 'windows-2019'
15+
break
2716

28-
// Ref. https://github.com/jenkins-infra/pipeline-library/pull/917
29-
def spotAgentSelector(String agentLabel, int counter) {
30-
// This function is defined in the jenkins-infra/pipeline-library
31-
if (infra.isTrusted()) {
32-
// Return early if on trusted (no spot agent)
33-
return agentLabel
34-
}
17+
// nanoserver-ltsc2022 and windowservercore-ltsc2022
18+
case ~/.*2022/:
19+
platform = 'windows-2022'
20+
break
21+
22+
// nanoserver-ltsc2025 and windowservercore-ltsc2025
23+
case ~/.*2025/:
24+
platform = 'windows-2025'
25+
break
3526

36-
if (counter > 1) {
37-
return agentLabel + ' && nonspot'
27+
// Linux
28+
default:
29+
// Need Docker and a LOT of memory for faster builds (due to multi archs)
30+
platform = 'docker-highmem'
31+
break
3832
}
3933

40-
return agentLabel + ' && spot'
34+
// Defined in https://github.com/jenkins-infra/pipeline-library/blob/master/vars/infra.groovy
35+
return infra.getBuildAgentLabel([
36+
useContainerAgent: false,
37+
platform: platform,
38+
spotRetryCounter: retryCounter
39+
])
4140
}
4241

4342
// Specify parallel stages
@@ -56,7 +55,7 @@ def parallelStages = [failFast: false]
5655
int retryCounter = 0
5756
retry(count: 2, conditions: [agent(), nonresumable()]) {
5857
// Use local variable to manage concurrency and increment BEFORE spinning up any agent
59-
final String resolvedAgentLabel = spotAgentSelector(agentSelector(imageType), retryCounter)
58+
final String resolvedAgentLabel = agentSelector(imageType, retryCounter)
6059
retryCounter++
6160
node(resolvedAgentLabel) {
6261
timeout(time: 60, unit: 'MINUTES') {

0 commit comments

Comments
 (0)