Mar*_*lon 1 bash find bash-scripting groovy jenkins
我试图在常规语法中的以下命令中使用反斜杠:
find /path/folder-* -type f -iname "file*" -exec rm -f {} \;
Run Code Online (Sandbox Code Playgroud)
当我尝试在 Jenkins 管道上构建此命令时,会出现有关此语法的错误。甚至在我执行此命令之前,Jenkins 表单字段上就会出现红色语法警告,提示意外字符:“\”。
我可以做什么来替换或修复这个反斜杠的错误?
Groovy 命令:
node ("instance") {
stage ("cleaning folders"){
sh '''
find /root/logfiles/instance* -type f -iname "file*" -exec rm -f {} \;
'''
}
stage ("instance1"){
sh '''
rm -f /root/logfiles/instance1/*
echo instance1;
scp 100.0.0.50:/var/log/file1.log /root/logfiles/instance1/file1.log;
scp 100.0.0.50:/var/log/file2.log /root/logfiles/instance1/file2.log;
'''
}
stage ("instance1"){
sh '''
rm -f /root/logfiles/instance2/*
echo instance2;
scp 100.0.0.51:/var/log/file1.log /root/logfiles/instance2/file1.log;
scp 100.0.0.51:/var/log/file2.log /root/logfiles/instance2/file2.log;
'''
}
}
Run Code Online (Sandbox Code Playgroud)
注意:rm -f目前我对所有情况都有。将全部替换rm -f为find舞台上清理文件夹的命令。
提前致谢
小智 5
这可能有助于逃脱你的逃脱角色,尽管这听起来很有趣。只需在反斜杠前面再加一个反斜杠即可:
stage ("cleaning folders"){
sh '''
find /root/logfiles/instance* -type f -iname "file*" -exec rm -f {} \\;
'''
}
Run Code Online (Sandbox Code Playgroud)
至少 IntelliJ 没有将其标记为语法错误。
| 归档时间: |
|
| 查看次数: |
34389 次 |
| 最近记录: |