Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

通过shell脚本来在Jenkins构建后往飞书群发送通知 #1

Open
xccjk opened this issue May 15, 2023 · 0 comments
Open

通过shell脚本来在Jenkins构建后往飞书群发送通知 #1

xccjk opened this issue May 15, 2023 · 0 comments

Comments

@xccjk
Copy link
Owner

xccjk commented May 15, 2023

#飞书通知
JOB_URL="${JENKINS_URL}job/${JOB_NAME}"
getBuildState(){
  buildNr=$1
  curl -u username:password ${JOB_URL}/${buildNr}/api/json |grep -Po '"result":\s*"\K\w+'
}
state=$(getBuildState ${BUILD_NUMBER}  )
JENKINS_URL=$JENKINS_URL
JOB_NAME=$JOB_NAME
GIT_BRANCH=$GIT_BRANCH
nowTime=$(date "+%Y-%m-%d %H:%M:%S")

if [[ "${state}" == "SUCCESS" ]] ; then
   curl -X POST -H "Content-Type: application/json" \
        -d '{
          "msg_type":"post",
          "content": {
            "post": {
              "zh_cn": {
                "title": "发布成功",
                "content": [
                  [
                    {"tag": "text", "text": "'"应用:$JOB_NAME\n"'"},
                    {"tag": "text", "text": "'"分支:"'"},
                    {"tag": "a", "href": "'"$GIT_URL"'", "text": "'"$GIT_BRANCH\n"'"},
                    {"tag": "text", "text": "'"状态:成功\n"'"},
                    {"tag": "text", "text": "'"构建:"'"},
                    {"tag": "a", "href": "'"${JOB_URL}/${buildNr}"'", "text": "'"$BUILD_DISPLAY_NAME\n"'"},
                    {"tag": "text", "text": "'"日期:$nowTime\n"'"}
                  ]
                ]
              }
            }
          }
        }' \
https://open.feishu.cn/open-apis/bot/v2/hook/xxx
else
   curl -X POST -H "Content-Type: application/json" \
        -d '{
          "msg_type":"post",
          "content": {
            "post": {
              "zh_cn": {
                "title": "发布失败",
                "content": [
                  [
                    {"tag": "text", "text": "'"应用:$JOB_NAME\n"'"},
                    {"tag": "text", "text": "'"分支:"'"},
                    {"tag": "a", "href": "'"$GIT_URL"'", "text": "'"$GIT_BRANCH\n"'"},
                    {"tag": "text", "text": "'"状态:失败\n"'"},
                    {"tag": "text", "text": "'"构建:"'"},
                    {"tag": "a", "href": "'"${JOB_URL}/${buildNr}"'", "text": "'"$BUILD_DISPLAY_NAME\n"'"},
                    {"tag": "text", "text": "'"日期:$nowTime\n"'"}
                  ]
                ]
              }
            }
          }
        }' \
https://open.feishu.cn/open-apis/bot/v2/hook/xxx
 
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant