我正在尝试在jenkins中运行shell脚本来重命名目录以在其中添加日期。
// rename file
sh("mv $file-reports $file-reports-$date")
sh("mv $file-reports-$date jmeter-tests")
日期由下一个脚本获取:
// Getting date
date = sh(
script: """
(date +%T-"%F")
""",
returnStdout: true
)
日期输出: 12:55:39-2018-07-26
我在日志中收到此错误:
[Pipeline] sh
[workspace] Running shell script
+ mv quickquote-belair-appstatic-reports quickquote-belair-appstatic-reports-15:59:27-2018-07-26a
[Pipeline] sh
[workspace] Running shell script
+ mv -T quickquote-belair-appstatic-reports-15:59:27-2018-07-26a
mv: missing destination file operand after ‘quickquote-belair-appstatic-reports-15:59:27-2018-07-26a’
Try 'mv --help' for more information.
我很困惑为什么它告诉我目标文件丢失了..?
答案 0 :(得分:0)
默认情况下,返回值sh()
后面将换行,因此您需要使用trim()
删除末尾的新行,如下所示:
date = sh(
script: """
(date +%T-"%F")
""",
returnStdout: true
).trim()
由于$date
在末尾有换行符,因此mv $file-reports-$date jmeter-tests
将在mv $file-reports-$date
处断开,目标jmeter-tests
将移至下一行。因此它报告mv miss destination file