首页 > 解决方案 > 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

Execute shell

标签: shelljenkins-pipeline

解决方案


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.


推荐阅读