在其中一个流水线步骤中,我进行了一次curl调用,效果很好:
<?php
$path = $_SERVER['DOCUMENT_ROOT'];
$path .= "/includes/connections/mysqli.php";
require($path);
$sql = "SELECT *
FROM tbl_photos_keywords_all
ORDER BY pa_keyword
";
$data = $link->query($sql);
$dataPoints = array();
while($row2 = $data->fetch_assoc()) {
$point = array("id" => $row2['pa_keywordID'], "name"=> htmlspecialchars($row2['pa_keyword']));
array_push($dataPoints, $point);
}
echo json_encode($dataPoints, JSON_NUMERIC_CHECK);
$link->close();
?>
如果在curl调用失败的情况下向该curl调用添加了if条件,则问题开始:
stage("deploy") {
when {
environment ignoreCase: true, name: "DEPLOY_TO", value: "staging"
}
steps {
// copy files from dev to server
sh """rsync...
#....
/bin/cp .....
rm -Rf /tmp/${env.SITEID}docs/
# clear the caches
curl -sS -X POST \"http://www.xxxxxxxx.net/myscript.php?api_key=sdfsdfsdfe&site_id=088\""""
错误现在指向代码行stage("deploy") {
when {
environment ignoreCase: true, name: "DEPLOY_TO", value: "staging"
}
steps {
// copy files from dev to server
sh """rsync...
#....
/bin/cp .....
rm -Rf /tmp/${env.SITEID}docs/
# clear the caches
if [[ $( curl -sS -X POST \"http://www.xxxxxxxx.net/myscript.php?api_key=sdfsdfsdfe&site_id=088\" | jq -r .debug_info.id_info) != \" cache cleared successfuly\" ]]; then exit 255; fi"""
,但困惑的是我什至没有更改代码行!
我收到的错误消息如下:
rm -Rf /tmp/${env.SITEID}docs/
感谢您的帮助。
答案 0 :(得分:1)
问题仍然在您修改的行中:
if [[ $( curl -sS -X POST \"http://www.xxxxxxxx.net/myscript.php?api_key=sdfsdfsdfe&site_id=088\" | jq -r .debug_info.id_info) != \" cache cleared successfuly\" ]]; then exit 255; fi
尽管输出行和列不正确,但是消息的正文是准确的。注意消息:
美元符号后的非法字符串体字符;
解决方案:要么转义文字美元符号“ \ $ 5”,要么将值表达式括在“ $ {5}”中
这是因为带有$( curl
的部分将美元符号解释为表示插在字符串中的Groovy和/或Jenkins变量。错误中给出的两个建议是基于您是否故意的。如果您的意思是这样,则需要将其括起来,例如:
${( curl...}
但是,由于您不是这个意思,而是想要在字符串内插入shell变量插值,因此您需要前面的建议并转义$
。
结果行如下:
if [[ \$( curl -sS -X POST \"http://www.xxxxxxxx.net/myscript.php?api_key=sdfsdfsdfe&site_id=088\" | jq -r .debug_info.id_info) != \" cache cleared successfuly\" ]]; then exit 255; fi