Shell脚本jenkins中的语法错误 [英] syntax error in shell script jenkins
问题描述
我正在使用jenkins,所以我试图在"执行shell "
I am using jenkins, so iam trying to execute below code in 'execute shell'
以下是脚本:
ssh user@prod-server
cd /myfolder
pwd
if [ ! -d myproj ]; then
git clone http://prod-server/bbb/myproj.git
else
cd myproj
pwd
git pull
fi
在"执行外壳程序"中,我尝试进行以下操作,但是在尝试构建时遇到语法错误:
In 'execute shell', iam trying as below but getting syntax errors while trying to build:
ssh prod-server 'cd /myfolder && pwd && if [ ! -d myproj ]; then git clone http://prod-server/bbb/myproj.git else cd myproj pwd git pull fi'
以下是语法错误:
Syntax error: end of file unexpected (expecting "fi")
所以,请告诉我要修改什么?
So, please tell me what to modify?
推荐答案
可能会出现语法错误,因为else树中的单个命令并未真正分开.您的shell(我认为是重击)应该如何知道命令的开始或结束位置?请尝试以下操作:
The syntax errors are to be expected, as the single commands in the else tree are not really separated. How should your shell (bash I presume) know where a command starts or ends? Try the following:
ssh prod-server 'cd /myfolder && pwd && if [ ! -d myproj ]; then git clone http://prod-server/bbb/myproj.git else cd myproj; pwd; git pull; fi'
或者,您也可以用&&
而不是;
分隔它们,从而仅在前一个命令成功后才执行下一个命令.
Alternatively, you can also separate them by &&
instead of ;
and thus execute the next command only when the former one succeeded.
这篇关于Shell脚本jenkins中的语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!