Jenkins error :54: expecting anything but ''\n''; got it anyway
Jenkins error :54: expecting anything but ''\n''; got it anyway
我在 jenkins 管道中使用以下 apache groovy 脚本将我的工件 (dev.ear) 部署到服务器。我在 groovy 中嵌入了 shell 脚本,以安全地将 dev.ear 从 jenkins slave 复制到目标服务器(unix 服务器)。
node('linux') {
stage('Checkout/Download/Deploy') {
timeout(time: 30, unit: 'MINUTES') {
def ziptmp = '.ziptmp'
output = sh returnStdout: true, script:"/bin/rm -rf ${ziptmp}; /bin/mkdir ${ziptmp}; cd ${ziptmp}; /usr/bin/unzip -qq ${tempdir}/${artifactFilename}; ls -ltr; echo *;
if [ -e dev.ear ]
then
scp dev.ear lsfi@${serverName57}:/apps/wls/dev/applications;
echo "COPIED DEV ARTIFACT TO SERVER"
else
echo "DEPLOYMENT PACKAGE DOESNT CONTAIN DEV ARTIFACT"
fi"
echo "RESULT::: ${output}"
}
}
}
触发 Jenkins 作业时出现以下错误
WorkflowScript: 54: expecting anything but ''\n''; got it anyway @ line 54, column 171.
ctFilename}; ls -ltr; echo *;
我删除了 shell 脚本中的新行并更新了如下代码:
def ziptmp = '.ziptmp'
output = sh returnStdout: true, script:"/bin/rm -rf ${ziptmp}; /bin/mkdir ${ziptmp}; cd ${ziptmp}; /usr/bin/unzip -qq ${tempdir}/${artifactFilename}; ls -ltr; echo *; if [ -e dev.ear ] then scp dev.ear lsfi@${serverName57}:/apps/wls/dev/applications; fi;"
echo "RESULT::: ${output}"
但我收到以下错误:
line 2: syntax error near unexpected token `fi'
如何解决这个错误。
Groovy 不喜欢 GString 中的换行符。根据 the Grails cookbook,您可以使用 '''Your multiline String'''
或 """Your multiline ${GString}"""
.
制作多行字符串
我不太确定 bash 语法,但根据 these docs.
,您似乎还缺少 if [ -e dev.ear ]
后的分号
综合起来:
output = sh returnStdout: true, script: """/bin/rm -rf ${ziptmp}; /bin/mkdir ${ziptmp}; cd ${ziptmp}; /usr/bin/unzip -qq ${tempdir}/${artifactFilename}; ls -ltr; echo *;
if [ -e dev.ear ];
then
scp dev.ear lsfi@${serverName57}:/apps/wls/dev/applications;
echo "COPIED DEV ARTIFACT TO SERVER"
else
echo "DEPLOYMENT PACKAGE DOESNT CONTAIN DEV ARTIFACT"
fi"
echo "RESULT::: ${output}"""
我在 jenkins 管道中使用以下 apache groovy 脚本将我的工件 (dev.ear) 部署到服务器。我在 groovy 中嵌入了 shell 脚本,以安全地将 dev.ear 从 jenkins slave 复制到目标服务器(unix 服务器)。
node('linux') {
stage('Checkout/Download/Deploy') {
timeout(time: 30, unit: 'MINUTES') {
def ziptmp = '.ziptmp'
output = sh returnStdout: true, script:"/bin/rm -rf ${ziptmp}; /bin/mkdir ${ziptmp}; cd ${ziptmp}; /usr/bin/unzip -qq ${tempdir}/${artifactFilename}; ls -ltr; echo *;
if [ -e dev.ear ]
then
scp dev.ear lsfi@${serverName57}:/apps/wls/dev/applications;
echo "COPIED DEV ARTIFACT TO SERVER"
else
echo "DEPLOYMENT PACKAGE DOESNT CONTAIN DEV ARTIFACT"
fi"
echo "RESULT::: ${output}"
}
}
}
触发 Jenkins 作业时出现以下错误
WorkflowScript: 54: expecting anything but ''\n''; got it anyway @ line 54, column 171.
ctFilename}; ls -ltr; echo *;
我删除了 shell 脚本中的新行并更新了如下代码:
def ziptmp = '.ziptmp'
output = sh returnStdout: true, script:"/bin/rm -rf ${ziptmp}; /bin/mkdir ${ziptmp}; cd ${ziptmp}; /usr/bin/unzip -qq ${tempdir}/${artifactFilename}; ls -ltr; echo *; if [ -e dev.ear ] then scp dev.ear lsfi@${serverName57}:/apps/wls/dev/applications; fi;"
echo "RESULT::: ${output}"
但我收到以下错误:
line 2: syntax error near unexpected token `fi'
如何解决这个错误。
Groovy 不喜欢 GString 中的换行符。根据 the Grails cookbook,您可以使用 '''Your multiline String'''
或 """Your multiline ${GString}"""
.
我不太确定 bash 语法,但根据 these docs.
,您似乎还缺少if [ -e dev.ear ]
后的分号
综合起来:
output = sh returnStdout: true, script: """/bin/rm -rf ${ziptmp}; /bin/mkdir ${ziptmp}; cd ${ziptmp}; /usr/bin/unzip -qq ${tempdir}/${artifactFilename}; ls -ltr; echo *;
if [ -e dev.ear ];
then
scp dev.ear lsfi@${serverName57}:/apps/wls/dev/applications;
echo "COPIED DEV ARTIFACT TO SERVER"
else
echo "DEPLOYMENT PACKAGE DOESNT CONTAIN DEV ARTIFACT"
fi"
echo "RESULT::: ${output}"""