Skip to content

Instantly share code, notes, and snippets.

@koolamusic
Forked from upggr/windows github webhook
Created February 16, 2018 11:54
Show Gist options
  • Save koolamusic/12ec58507063cdc46bf100490f101e9d to your computer and use it in GitHub Desktop.
Save koolamusic/12ec58507063cdc46bf100490f101e9d to your computer and use it in GitHub Desktop.
Workflow for automated github pull on windows
On the github website there is guide detailing a worfklow for the developer that wants to have continuous integration on a linux server.
This has been detailed in many gists and goes like this in its simplest form :
1.git clone on your public_html folder (after you create ssh keys etc)
2.create a file gitpull.php with the command : exec(git pull); inside it
3.create a webhook on github to call yourwebsite.com/gitpull.php
What about windows though? you can install git bash, but the above will not work because of permissions, mostly because the user that will invoke the url will be whatever user is running the process that calls php (for example SYSTEM or IUSR)
I have a better, clever solution for that, that uses.. the windows log! Also great for troubleshooting your deployments:
1.git clone your repo in your htdocs folder (taking for example xampp on windows) or even IIS
2.create a file github_pull_win.php with contents : exec('eventcreate /ID 1 /L APPLICATION /T INFORMATION /SO YOUR_APPLICATION_NAME /D "git webhook"',$return,$output); (Replacing your YOUR_APPLICATION_NAME with something)
3.create a file pull.bat with "git pull" in it
4.invoke the file once using "php github_pull_win.php"
5.start the task scheduler on windows
6.Add a new task that triggers "On event - Log: Application, Source:YOUR_APPLICATION_NAME,Event ID:1"
7.Set the action of this task to run the file : pull.bat using your user that holds the keys.
Done! Continuous deployment on windows
You could also modify the above to include the actual git message rather than just "git webhook"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment