Skip to content

Commit 4c96d82

Browse files
committed
feat(module): add slurm module for swx-jenkins-lib integration
Adds vars/slurmCi.groovy, a ci-demo action module that loads the slurm swx-jenkins-lib Jenkins shared library and dispatches Slurm HPC operations (allocation, run, stop, stopAllForBuild) from matrix YAML steps using shell: action + module: slurm. Signed-off-by: Daniel Pressler <danielpr@nvidia.com>
1 parent 805cf3b commit 4c96d82

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

vars/slurmCI.groovy

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env groovy
2+
3+
int call(ctx, oneStep, config) {
4+
def args = oneStep.args ?: [:]
5+
6+
// Load the shared Slurm helper library from the pipeline shared library.
7+
// refer to this doc for more details: https://www.jenkins.io/doc/book/pipeline/shared-libraries/#using-libraries
8+
// Default is 'swx-jenkins-lib' (from Mellanox-lab org). Optional step arg 'ref' can override the git ref.
9+
// e.g., args: [ref: 'my-branch'] => library(identifier: 'swx-jenkins-lib@my-branch')
10+
def libRef = args.remove('ref')
11+
12+
if (libRef) {
13+
library(identifier: "swx-jenkins-lib@${libRef}")
14+
} else {
15+
library('swx-jenkins-lib')
16+
}
17+
18+
if (!args || args.size() < 1) {
19+
ctx.reportFail(oneStep.name, 'fatal: slurm module expects at least 1 arg')
20+
return 1
21+
}
22+
23+
for (def entry in ctx.entrySet(args)) {
24+
args[entry.key] = ctx.resolveTemplate(['env': env], entry.value.toString(), config)
25+
}
26+
def stepRun = oneStep.run
27+
def allowedOps = ['allocation', 'run', 'stop', 'stopAllForBuild'] as Set
28+
if (!allowedOps.contains(stepRun)) {
29+
ctx.reportFail(oneStep.name, "fatal: unsupported slurm operation '${stepRun}'; allowed: ${allowedOps.sort().join(', ')}")
30+
return 1
31+
}
32+
println("Calling slurm.${stepRun} with args=" + args)
33+
34+
def vars = []
35+
vars += ctx.toEnvVars(config, config.env)
36+
vars += ctx.toEnvVars(config, oneStep.env)
37+
38+
def rawResult = null
39+
withEnv(vars) {
40+
rawResult = slurm."${stepRun}"(args)
41+
}
42+
if (rawResult == false) {
43+
return 1
44+
}
45+
if (rawResult instanceof Number) {
46+
return (rawResult as int)
47+
}
48+
return 0
49+
}

0 commit comments

Comments
 (0)