| I suspect that the two executions are differing in shell: bash vs. traditional sh / dash. At any rate, it is hard to follow your string escapes there. I strongly recommend using single quotes for sh steps, not only to improve legibility but to ensure you do not accidentally use GString interpolation (which is rarely what you want—see inline help for withCredentials for the gory details). If the command itself has single quotes, use a Groovy multiline string:
sh '''
find . -path '*/target/*/screenshots' …
'''
which will be more readable. Or better yet, just move all this stuff into your regular build script so it produces the desired artifacts in a tidy directory ready for Jenkins to publish, which is something you can easily test locally. There is no reason to clutter Jenkinsfile with complex embedded scripts. Not sure why cleaning a directory would be complex in any setup. rm -rf tmp-jenkins-png && mkdir tmp-jenkins-png does not suffice? |