Created
March 12, 2021 13:25
-
-
Save mad01/d85af0d59c5a1a864efac5b41649fe6f to your computer and use it in GitHub Desktop.
Shell script to add webook config for jenkins
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 - | |
set -o nounset | |
ORG=foo | |
REPO=bar | |
JENKINS_URL="https://jenkins.com/github-webhook/" | |
PAYLOAD=$( | |
echo '{"events": ["push", "pull_request"], "config":{"url":"$JENKINS_URL","content_type":"json","secret":"$WEBHOOK_SECRET","insecure_ssl":"0"}}' \ | |
| jq -r \ | |
--arg url "$JENKINS_URL" \ | |
--arg secret "$WEBHOOK_SECRET" \ | |
'.config.url = $url | .config.secret = $secret' | |
) | |
echo $PAYLOAD | |
# config | |
curl \ | |
-X POST \ | |
-u $GITHUB_USER:$GITHUB_TOKEN \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
https://api.github.com/repos/"${ORG}/${REPO}"/hooks \ | |
--data "$PAYLOAD" | |
# get webhook config | |
curl -s \ | |
-u $GITHUB_USER:$GITHUB_TOKEN \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
https://api.github.com/repos/"${ORG}/${REPO}"/hooks | jq -r | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment