[英]How to add shell script to jenkins pipeline
我有以下 shell 脚本:
du -sh /bbhome/shared/data/repositories/* |sort -h |tail -20 |
while IFS= read -r line;do
DIR=`echo $line | awk '{print$2}'`
Rep=`cat $DIR/repository-config |grep 'project\|repo' | tr '\n' ' '`
Size=`echo $line | awk '{print $1}' `
echo $Size $Rep
done
我如何在 Jenkins 中运行它认为 Execute shell? 我还需要向 env 添加 ssh 命令(不需要密码)。 注意我不想连接到 env 并运行这个 shell,而是直接从 Excecue shell box
如果我没有错,您使用的是 Freestyle 作业而不是管道作业。 无论如何,我认为您必须尝试以下操作:
ssh -t XXXXX@YYYYY << 'EOF' du -sh /bbhome/shared/data/repositories/* |sort -h |tail -20 | while IFS= read -r line;do\\ DIR=
ssh -t XXXXX@YYYYY << 'EOF' du -sh /bbhome/shared/data/repositories/* |sort -h |tail -20 | while IFS= read -r line;do\\ DIR=
echo $line | awk '{print$2}' \\ Rep=
cat $DIR/repository-config |grep 'project\\|repo' | tr '\\n' ' ' \\ Size=
echo $line | awk '{print $1}' \\ echo $Size $Rep\\ done EOF
我已经使用 \\ 对你的 while 循环中的代码进行了转义,如果它不起作用你可以使用 ; 反而。
如果您需要有关使用管道作业的帮助,请告诉我,但我可能会更复杂一些。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.