Skip to content

Instantly share code, notes, and snippets.

@yogeshlonkar
Last active October 23, 2018 06:08
Show Gist options
  • Save yogeshlonkar/d6190eff38e06aaf7d70630b2f1c6e37 to your computer and use it in GitHub Desktop.
Save yogeshlonkar/d6190eff38e06aaf7d70630b2f1c6e37 to your computer and use it in GitHub Desktop.
On Current directory change Git commit & push, Trigger Jenkins and refresh current tab
#!/bin/bash -e
GREEN='\033[0;32m'
# watch current directory for change
fswatch -o ./* | while read -d 1; do
# commit and push
git add . && git commit --no-status -m "jenkins-test" && git push -q
printf "\n${GREEN}-> commit & push done\n"
# Jenkins trigger
JKSERVER="http://localhost:8080"
JKUSER="$1"
JKPASSWORD="$2"
JKCRUMB=$(wget -q --auth-no-challenge --user $JKUSER --password $JKPASSWORD --output-document - "$JKSERVER/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,\":\",//crumb)")
curl --user $JKUSER:$JKPASSWORD -X POST "$JKSERVER/job/XYZ/buildWithParameters" -H "$JKCRUMB" --data token=test_deploy
printf "\n${GREEN}-> jenkins job triggered\n"
# safari refresh current tab which should be http://localhost:8080/job/XYZ/lastBuild/console
osascript -e '
tell application "Safari"
activate
tell current tab of window 1
do JavaScript "location.reload();"
end tell
end tell
'
printf "\n${GREEN}-> safari tab refreshed\n"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment