我尝试在gitlab CI中实现一个脚本,通过Jenkins触发烟雾测试,然后获得结果。
到目前为止,我能够成功触发作业,我正试图遵循这一点来实现一个监视阶段,然后在作业完成后获得结果。
我的问题是,我实现了一个while循环来监控Jenkins作业是否已经完成,到目前为止脚本是否出现语法错误(当在gitlab中复制时),或者如果在终端中运行,我会得到:
job is building? true
waiting...
parse error: Invalid numeric literal at line 2, column 0
job is still building?
job is building?
这是我目前使用的:
#!/bin/bash
running="true"
while [ "$running" != "false" ]
do
echo "job is building? ${running}"
echo "waiting...";
sleep 2;
running=$(curl -s --user ${EMAIL}:${TOKEN} ${URL}/${var}/lastBuild/api/json | jq .'building')
echo "job is still building? ${running}"
done
echo "Done!"
buildNumber=$(curl -s --user $EMAIL:$TOKEN ${URL}/$ENV-${var}/lastBuild/api/json | jq ".url" | awk -F "/" '{print $(NF-1)}')
echo "getting results for build ${buildNumber}"
curl -s --user ${EMAIL}:${TOKEN} ${URL}/${ENV}-${var}/lastBuild/api/json | jq ".url" | awk -F "/" '{print $(NF-1)}'
curl -v --silent --user ${EMAIL}:${TOKEN} ${URL}/${ENV}-${var}/lastBuild/consoleText 2>&1 | grep -i "finished:"
- 更新**
这脚本是运行现在ok在我的本地终端
变化是
running="true"
while [ "$running" != "false" ]
do
echo "job is building? ${running}"
echo "waiting..."
sleep 2
curl -s --user $EMAIL:$TOKEN $URL/$ENV-${var}/lastBuild/api/json --output now.txt
running=$(jq .'building' now.txt)
echo "job is still building? ${running}"
done
问题仍然在Gitlab CI上,因为在复制粘贴此脚本后,我进入了管道
/bin/sh: eval: line 149: syntax error: unexpected "done"
1条答案
按热度按时间dfddblmv1#
我猜这个错误
来自于 curl 的线条
我假设这个错误是
jq
在解析json失败时抛出的,因为这一行有错误,变量running
从来没有得到正确的更新,这意味着脚本的其余部分没有按预期工作。如果你修复了这一行,你的管道的其余部分应该工作。考虑一下this question,它有一个类似的问题和一些解决方案。