shell - How to add shell script to jenkins pipeline
问题描述
I have the below shell script:
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
How can I run it thought Execute shell in Jenkins? I need also to add ssh command to the env (no need for a password). Note I don't want to connect to the env and run this shell, but directly from Excecue shell box
解决方案
If I'm not wrong your are using a Freestyle job and not a pipeline job. Anyway, I think you have to try the following :
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
I've escaped the code inside your while loop using \, if it's doesn't works you can use ; instead.
If you want help for using a pipeline job, let me know but i might be a bit more complex.
推荐阅读
- python - Tweepy 的 StreamListener 与 async 结合
- javascript - 如何使用 redux 在 saga 中执行多个操作并跟踪组件中的整体成功/失败?
- java - 带有多个点的 messages.properties 键不起作用
- makefile - 将路径添加到目标的通用规则
- typo3 - TYPO3 流体项目 -> f:count() 选择字段和 f:widget.paginate
- r - 从父类调用 setup_data
- swift - 在屏幕边缘定位形状
- linux - 使用 scanf 的程序中的分段错误
- react-native - 如何在反应原生中将数据从一个屏幕传递到 TabNavigator 内的另一个屏幕
- c# - 用于收集沿袭 ID 的 SSIS 脚本任务