Skip to content

Instantly share code, notes, and snippets.

@hakanai
Last active May 24, 2019 06:40
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save hakanai/207c6d14617003c04611811bef36977c to your computer and use it in GitHub Desktop.
Is it possible to do _this_ in Jenkins pipeline?
// TODO: What does call actually return? Is it void?
def call(Closure body) {
// Call the body of the block and capture it into variables
Map<String, Object> config = [:]
body.resolveStrategy = Closure.DELEGATE_FIRST
body.delegate = config
body()
Closure template = (Closure) config.template
List<List<Object>> matrix = (List<List<Object>>) config.matrix
template.resolveStrategy = Closure.DELEGATE_FIRST
for (List<Object> oneRun : matrix) {
template.delegate = oneRun
template()
}
}
pipeline {
// ...
stages {
// ...
customMatrix {
matrix [name: 'debian', prettyName: 'Debian'],
[name: 'ubuntu', prettyName: 'Ubuntu'],
[name: 'centos', prettyName: 'CentOS'],
[name: 'macos', prettyName: 'macOS'],
[name: 'windows', prettyName: 'Windows']
template {
stage("Test on ${prettyName}") {
agent {
label name
}
steps {
unstash 'compile-artifacts'
unstash 'dot-gradle'
gradle tasks: 'check', switches: '--stacktrace'
}
post {
always {
junit '*/build/test-results/**/*.xml'
}
}
}
}
}
// ...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment