In our Jenkins pipeline we have following command
if(!fileExists("dist/main/sourcemaps/")) {
sh "curl ${SERVER_URL}/${revision}.zip -o artifact.zip"
sh 'unzip artifact.zip -d dist && mv dist/main/* dist/'
}
Which cause following error
mv: can't rename 'dist/main/sourcemaps': File exists
I don't understand why fileExists method doesn't check folder existence and how to fix this problem
Solution:
I was smart enough to check not a destination directory, but a source directory. It should be as follows:
if(!fileExists("dist/sourcemaps/")) {
sh "curl ${SERVER_URL}/${revision}.zip -o artifact.zip"
sh 'unzip artifact.zip -d dist && mv dist/main/* dist/'
}
although we've refactored it to more bash-style implementation
if [ ! -d dist/sourcemaps ]; then
curl ${SERVER_URL}/${revision}.zip -o artifact.zip
unzip artifact.zip -d dist && mv dist/main/* dist/
fi