Jenkinsfile script to waitUntil a folder is created With this Jenkinsfile code, I am trying to test A/B folder creation, and also testing if waitUntil works till the folder is created, I expect it to wait for 0 secs as the folder is created before waitUntil gets called.

stage('other job') {
                    steps {
                        script {
                            timeout(10) {
                                def folder = new File( 'A/B' )
                                println "Waiting for " + folder
                                println "fe==" + folder.exists()
                                waitUntil {
                                    if(folder.exists()) {
                                        return(true)
                                    }
                                }
                            }
                        }
                    }
                }


It fails with below error, what's wrong here? the folder is not gerrit created in workspace.

Timeout set to expire in 10 min
[Pipeline] {
[Pipeline] // stage
[Pipeline] }
[Pipeline] echo
Waiting for A/B
[Pipeline] echo
fe==false
[Pipeline] waitUntil
[Pipeline] {
[Pipeline] }
[Pipeline] // waitUntil
[Pipeline] }
[Pipeline] // timeout
...
Failed in branch other job
...
[Pipeline] End of Pipeline
java.lang.ClassCastException: body return value null is not boolean
    at org.jenkinsci.plugins.workflow.steps.WaitForConditionStep$Callback.onSuccess(WaitForConditionStep.java:167)
    at org.jenkinsci.plugins.workflow.cps.CpsBodyExecution$SuccessAdapter.receive(CpsBodyExecution.java:377)
Your block expression doesn't return a value in all cases.

Try this instead:

waitUntil { folder.exists() }