shell中curl请求变更使用markdown

如果使用变量,得换成双引号,数据里面也有双引号,加转义字符即可。
  curl 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=d1b0f47c-9b50-452b-8467-e681e181af28' \
   -H 'Content-Type: application/json' \
  -d "
   {
    \"msgtype\": \"markdown\",
    \"markdown\": {
        \"content\": \"[发票主流程构建失败报告](${TEST_REPORT})\"
    }
}"

 

完整示例:

#!/bin/bash
file="src/main/resources/config.properties"
/usr/bin/sed -i  "s/env=.*/env=${env}/g" ${file}

PROJECT_NAME=$JOB_NAME;
BUILD_NUM=$BUILD_NUMBER;

[[  $PROJECT_NAME = "" ]] && echo "工程名参数为空" && exit 1
[[  $BUILD_NUM = "" ]] && echo "构建id参数为空" && exit 1

TEST_REPORT="http://10.199.137.177:8080/jenkins/job/${PROJECT_NAME}/${BUILD_NUM}/allure/#suites"
echo ">>>>>>>>TEST_REPORT:${TEST_REPORT}"


mvn clean test -DxmlFileName=${xmlFileName}

if [[ $? = 0  ]];then
       curl 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=d1b0f47c-9b50-452b-8467-e681e181af28' \
   -H 'Content-Type: application/json' \
   -d "
   {
    \"msgtype\": \"markdown\",
    \"markdown\": {
        \"content\": \"[发票主流程构建成功,点击查看测试报告](${TEST_REPORT})\"
    }
}";
        exit 0
else

               curl 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=d1b0f47c-9b50-452b-8467-e681e181af28' \
   -H 'Content-Type: application/json' \
  -d "
   {
    \"msgtype\": \"markdown\",
    \"markdown\": {
        \"content\": \"[发票主流程构建失败报告](${TEST_REPORT})\"
    }
}";
        exit 1
fi

©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页