Last active
May 4, 2021 02:31
-
-
Save StevenACoffman/ed2b9b5aceb5db0da9fd1c2f512c3158 to your computer and use it in GitHub Desktop.
Jenkins Scripts For Build Status to Github Pull Request
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#Jenkins provides: | |
#GIT_COMMIT like ce9a3c1404e8c91be604088670e93434c4253f03 | |
#GIT_BRANCH like origin/master | |
#BUILD_URL like http://jenkins.test.cirrostratus.org/job/Article_View_c20n_Full_Non_Destructive_Full_Suite/1334/ | |
# per https://wiki.jenkins-ci.org/display/JENKINS/GitHub+pull+request+builder+plugin | |
# The jenkins pull request builder plugin (if configured) will provide these: | |
#ghprbPullId | |
#ghprbActualCommit | |
#ghprbActualCommitAuthor | |
#ghprbActualCommitAuthorEmail | |
#ghprbPullDescription | |
#ghprbPullId | |
#ghprbPullLink | |
#ghprbPullTitle | |
#ghprbSourceBranch | |
#ghprbTargetBranch | |
#sha1 | |
#Run these functions like this: | |
# BUILD_URL="";gh_post_success_comment "mylists-service" "48" | |
function gh_post_success_comment() { | |
#Expects that the GITHUB_AUTH_TOKEN is provided already in the environment | |
#Expects that BUILD_URL is provided already in the environment | |
# 1st required argument is the repository name like "jstor" or "mylists-service" | |
# 2nd required argument is the pull request number | |
# 3rd optional argument is the message itself | |
REPO="${1:-please-specify-repo}" | |
PULL_REQUEST_NUMBER="${2:-please-specify-pr-number}" | |
COMMENT_DEFAULT=":white_check_mark: [All Checks Passed](${BUILD_URL})" | |
COMMENT_MARKDOWN="${3:-$COMMENT_DEFAULT}" | |
curl -v -H "Content-Type: application/json" \ | |
-H "Authorization: token ${GITHUB_AUTH_TOKEN}" \ | |
-X POST \ | |
-d "{\"body\":\"${COMMENT_MARKDOWN}\"}" \ | |
"https://api.github.com/repos/ithaka/${REPO}/issues/${PULL_REQUEST_NUMBER}/comments" | |
} | |
function gh_post_failure_comment() { | |
#Expects that the GITHUB_AUTH_TOKEN is provided already in the environment | |
#Expects that BUILD_URL is provided already in the environment | |
# 1st required argument is the repository name like "jstor" or "mylists-service" | |
# 2nd required argument is the pull request number | |
# 3rd optional argument is the message itself | |
REPO="${1:-please-specify-repo}" | |
PULL_REQUEST_NUMBER="${2:-please-specify-pr-number}" | |
COMMENT_DEFAULT=":x: [Failure](${BUILD_URL})" | |
COMMENT_MARKDOWN="${3:-$COMMENT_DEFAULT}" | |
curl -v -H "Content-Type: application/json" \ | |
-H "Authorization: token ${GITHUB_AUTH_TOKEN}" \ | |
-X POST \ | |
-d "{\"body\":\"${COMMENT_MARKDOWN}\"}" \ | |
"https://api.github.com/repos/ithaka/${REPO}/issues/${PULL_REQUEST_NUMBER}/comments" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment