Created
May 22, 2018 18:12
-
-
Save ddgenome/66942350efe7f6d58613f5a8562d0505 to your computer and use it in GitHub Desktop.
Atomist Link Image Webhook - Codeship
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 | |
# link-image post one-liner for codeship | |
# Codeship sets CI_REPO_NAME and CI_COMMIT_ID, you must set DOCKER_IMAGE and ATOMIST_TEAM | |
# ATOMIST_TEAM should be your Atomist workspace/team ID | |
curl -s -f -X POST -H "Content-Type: application/json" \ | |
--data-binary "{\"git\":{\"owner\":\"${CI_REPO_NAME%/*}\",\"repo\":\"${CI_REPO_NAME#*/}\",\"sha\":\"$CI_COMMIT_ID\"},\"docker\":{\"image\":\"$DOCKER_IMAGE\"},\"type\":\"link-image\"}" \ | |
https://webhook.atomist.com/atomist/link-image/teams/$ATOMIST_TEAM | |
# Or, if you prefer to call a function, use this instead | |
# create a link between a docker image and a commit | |
# usage: link-image-codeship DOCKER_IMAGE | |
function link-image-codeship () { | |
local image=$1 | |
if [[ ! $image ]]; then | |
err "link-image: missing required argument: DOCKER_IMAGE" | |
return 10 | |
fi | |
shift | |
if [[ ! $ATOMIST_TEAM ]]; then | |
msg "no Atomist team set" | |
msg "not creating docker image-commit link" | |
return 0 | |
fi | |
local url=https://webhook.atomist.com/atomist/link-image/teams/$ATOMIST_TEAM | |
local owner=${CI_REPO_NAME%/*} | |
local repo=${CI_REPO_NAME#*/} | |
local sha=$CI_COMMIT_ID | |
local payload | |
printf -v payload '{"git":{"owner":"%s","repo":"%s","sha":"%s"},"docker":{"image":"%s"},"type":"link-image"}' "$owner" "$repo" "$sha" "$image" | |
msg "posting image-link payload to '$url': '$payload'" | |
if ! curl -s -f -X POST -H "Content-Type: application/json" --data-binary "$payload" "$url" > /dev/null 2>&1 | |
then | |
err "failed to post payload '$payload' to '$url'" | |
return 1 | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment