Skip to content

Instantly share code, notes, and snippets.

@scorpp
Created November 11, 2016 17:39
Show Gist options
  • Save scorpp/4f40dfab53c93b574b6c5cce4066032e to your computer and use it in GitHub Desktop.
Save scorpp/4f40dfab53c93b574b6c5cce4066032e to your computer and use it in GitHub Desktop.
Jenkins script to upgrade a service on Rancher
test -f JSON.sh || curl -O https://raw.githubusercontent.com/dominictarr/JSON.sh/master/JSON.sh
eval $(sed 's/^/MY_/' build.info)
ORIG_LAUNCH_CONFIG=$(cat my-app-service.json | bash ./JSON.sh | grep -F '["launchConfig"]' | sed -e 's/[^{]*//')
NEW_LAUNGH_CONFIG=$(echo $ORIG_LAUNCH_CONFIG |\
sed "s/\(\"imageUuid\"\):\"[^\"]*\"/\1:\"docker:my-image:${MY_BUILD_NUMBER}\"/")
echo $NEW_LAUNGH_CONFIG |\
xargs -d\\n -i_-_ curl -v -u "RANCHER_KEY:RANCHER_SECRET" \
-X POST -H 'Content-Type: application/json' \
-d '{"inServiceStrategy":{"launchConfig": _-_ }}' \
http://rancher-server/v1/services/1s10?action=upgrade
sleep 60
# confirm upgrade
curl -v -u "RANCHER_KEY:RANCHER_SECRET" \
-X POST http://rancher-server/v1/services/1s10?action=finishupgrade
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment