I want to wrap steps
and post
in a function.
This works fine:
pipeline {
agent any
stages {
stage('Test') {
steps {
whateverFunction()
}
post {
sh 'echo test'
}
}
}
}
void whateverFunction() {
sh 'ls /'
}
But as soon as I pack steps and post in my function it does not work. (Fail's with the error: steps in a stage must be in a ‘steps’ block.
)
pipeline {
agent any
stages {
stage('Test') {
whateverFunction()
}
}
}
void whateverFunction() {
steps {
sh 'echo test'
}
post {
sh 'echo test'
}
}
What I also tried is to have steps
and then call my function in that step with a steps
inside. Basically warping steps
in steps
which leads to the behavior that no step is executed. (But apparently it would be a valid Jenkins-file)
Is it possible to have a function which contains steps
and post
inside a stage. Or is there a way to achieve a similar functionality?