actions-ding/docker/entrypoint.sh

30 lines
613 B
Bash
Raw Normal View History

2019-08-26 14:36:42 +08:00
#!/bin/sh -l
2019-08-26 15:37:16 +08:00
if [ -z "${INPUT_DINGTOKEN}" ]
then
echo "dingToken is required!"
exit 1
fi
2019-08-29 16:48:20 +08:00
if [ -z "${INPUT_BODY}" ]
2019-08-26 15:37:16 +08:00
then
2019-08-29 16:48:20 +08:00
echo "body is required!"
2019-08-26 15:37:16 +08:00
exit 1
fi
2019-08-29 16:48:20 +08:00
echo "body: $INPUT_BODY"
2019-08-26 15:24:49 +08:00
2019-08-29 16:48:20 +08:00
url="https://oapi.dingtalk.com/robot/send?access_token=${INPUT_DINGTOKEN}"
2019-08-27 17:37:45 +08:00
2019-08-29 17:30:31 +08:00
HTTP_RESPONSE=$(curl -s --write-out "HTTPSTATUS:%{http_code}" "$url" \
2019-08-26 15:24:49 +08:00
-H 'Content-Type: application/json' \
2019-08-29 17:30:31 +08:00
-d "${INPUT_BODY}")
# extract the body
HTTP_BODY=$(echo "$HTTP_RESPONSE" | sed -e 's/HTTPSTATUS\:.*//g')
if [ ! "$HTTP_BODY" = '{"errcode":0,"errmsg":"ok"}' ]; then
echo "Error Response: ${HTTP_RESPONSE}"
exit 1
fi