Skip to content

Instantly share code, notes, and snippets.

@bhenderson
Created May 16, 2017 22:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bhenderson/fc44192a980df3b2a2852a65d0dd5621 to your computer and use it in GitHub Desktop.
Save bhenderson/fc44192a980df3b2a2852a65d0dd5621 to your computer and use it in GitHub Desktop.
Jenkinsfile with validation dsl (does not work!)
validator {
validate 'hello'
validate 'world'
}
[Pipeline] node
Running on master in /var/jenkins_home/workspace/validator
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Validate)
[Pipeline] echo
hello
[Pipeline] echo
world
[Pipeline] }
[Pipeline] }
[Pipeline] End of Pipeline
Finished: FAILURE
// src/conveyor/Validator.groovy
package conveyor
class Validator {
def messages = []
def validate(String msg) {
messages.add(msg)
}
}
// vars/validator.groovy
import conveyor.Validator
def call(Closure body) {
def validator = new Validator()
body.resolveStrategy = Closure.DELEGATE_FIRST
body.delegate = validator
body()
node('master') {
stage('Validate') {
for(def m : validator.messages) {
echo(m)
}
}
}
}
@bhenderson
Copy link
Author

Why does the pipeline fail?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment