Skip to content

Instantly share code, notes, and snippets.

@mad01
Created March 12, 2021 13:25
Show Gist options
  • Save mad01/d85af0d59c5a1a864efac5b41649fe6f to your computer and use it in GitHub Desktop.
Save mad01/d85af0d59c5a1a864efac5b41649fe6f to your computer and use it in GitHub Desktop.
Shell script to add webook config for jenkins
#!/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