Open pcoulso1 opened 4 years ago
Other conditions (like not
) are not working either:
...
stage('Example Test') {
when {
not {
expression { return false }
}
}
agent { docker 'openjdk:8-jre' }
...
Is there any way to workaround this in my own test code? I have tried,
testee = loadScript("vars/mypipeline.groovy")
helper.registerAllowedMethod("anyOf", [Closure.class], { it -> it() })
testee.call()
But still same exception.
Sorry if this is somewhere explained, but I could not find it and I'm totally groovy-newbie.
Hey @pcoulso1.
I recently added support for anyOf
here.
It shouldn't be hard to replicate the behavior for allOf
Hi @IuryAlves
The implementation of anyOf you made only work for a single validation inside anyOf.
anyOf { branch 'master' }
In this case works to check if the branch is master or not.
If we have more than one validation e will only validate the last one
anyOf { branch 'master'; branch 'release'; branch 'develop' }
In this case if the branch is master it will be false, but if it is develop it will be true.
Do you know how to make this to work as a "anyOf" behaviour ? Thanks
Hey @epsilo
You're right!
I have done a new PR for adding support to multiple validations for branch
and expression
.
Bear in mind that there are other validations still missing.
Thank you very much!
@epsilo My PR was merged. Can you try again?
@IuryAlves it is working great now! Thanks
Nice. I think this issue can be closed now.
Technically The issue covered BeforeAgent as well which is not implemented yet, therefore the issue might be still open
e.g:
groovy.lang.MissingMethodException: No signature of method: Jenkinsfile.beforeAgent() is applicable for argument types: (Boolean) values: [true]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
And the Jenkins File
stage('Before Agent Test') {
when {
beforeAgent true
not { branch MY_BRANCH }
}
steps {
script {
....
}
}
}
Hi, Just wondering if any update on the issue to support BeforeAgent? the left issue quoted by @jcmendez-guerrero .. Thanks!
I don't see an assignee on the issue, could someone provide an update for it?
I faced the same problems and created a pull request to solve the issue.
Thx for merging @nre-ableton. I guess we can close this issue here. Any plans on when a new tag will be created?
Thx for merging @nre-ableton. I guess we can close this issue here. Any plans on when a new tag will be created?
I'll try to make a release sometime this week when I have some time.
The class WhenDeclaration in com.lesfurets.jenkins.unit.declarative seems to be missing the option for 'beforeAgent', 'anyOf' and 'allOf'
e.g. when used in the stage section of the jenkinsfile
And results in the following exception when the tests are run
See https://www.jenkins.io/doc/book/pipeline/syntax/ for details