如果 jenkins 声明管道中的文件夹中有 space,你如何获得工作space?

How can you get the workspace if there is a space in the folder in jenkins declarative pipeline ]?

我对 jenkins 还是很陌生,当时我正在处理管道,工作space路径如下: workspace/folder withspace/Pipeline。我正在尝试向 jenkins 授予 运行 一个 bash 脚本的权限,但是由于文件夹名称中的 space 我收到错误消息:

chmod: cannot access /workspace/folder’: No such file or directory
chmod: cannot access ‘withspace/Pipeline’: No such file or directory.

我知道删除文件夹名称中的 space 可以解决问题,但我被要求在不删除 space 的情况下解决此问题。 Here are the lines in my code causing the error感谢您的建议和帮助!

在 Bash 中,您可以使用引号将整个路径括起来,或者使用反斜杠对每个 space 字符进行转义。
你的情况因为不控制值,所以需要引用workspace path:

sh "chmod +x -R \"${env.WORKSPACE}\""