Reputation: 1375
I try to make simple pipeline
on Jenkins
to remove files from few directories time to time. I decided not to create python
script with Jenkinsfile
as new project, instead of it I try to define new pipeline
script in Jenkins
job.
pipeline {
agent any
stages {
stage('Check virtualenv') {
steps {
sh """
rm -r /mnt/x/some/directory/Problem\ 1.0/path
"""
}
}
}
}
And I got an error WorkflowScript: 4: unexpected char: '\'
. How can I use path with whitespace on it without using backslash? Any other ideas how define path?
Upvotes: 29
Views: 55981
Reputation: 47269
The '\'
character is a special character in Groovy. If you tried to compile this kind of code with the normal Groovy compiler, it would give you a better error message. The easiest way to handle it would be to escape it:
"""
rm -r /mnt/x/some/directory/Problem\\ 1.0/path
"""
Upvotes: 57
Reputation: 5451
You can modify the shell command as follows:
sh """
rm -r /mnt/x/some/directory/Problem""" + """ 1.0/path"""
Provide space before 1.0 as required. Hope this helps.
Upvotes: 3