Skip to content

A simple GitHub post-receive web hook handler able to trigger a CircleCI build.

License

Notifications You must be signed in to change notification settings

Slicer/github-circleci-trigger

Repository files navigation

GitHub CircleCI Trigger

A simple GitHub post-receive web hook handler able to trigger a CircleCI build.

motivation

It is particularly useful for triggering CircleCI build using GitHub token.

quickstart

First, from a terminal, install and start the server

# create virtualenv
$ mkvirtualenvwrapper github-circleci-trigger

# choose CircleCI project to trigger
$ export CIRCLECI_REPO=orgname/worker-with-privileges
$ export CIRCLECI_TOKEN=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

# install server
$ git clone https://github.com/Slicer/github-circleci-trigger
$ pip install -r github-circleci-trigger/requirements.txt

# start server
$ cd github-circleci-trigger
$ FLASK_APP="github-circleci-trigger.py"
$ GITHUB_WEBHOOK_SECRET="This is a secret"
$ FLASK_DEBUG="1"
$ python -m flask run
 * Serving Flask app "github-circleci-trigger"
 * Forcing debug mode on
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

Then, open the URL http://127.0.0.1:5000 in your favorite browser. It should display Hello World! on the page and report the following in your terminal:

127.0.0.1 - - [25/Mar/2017 04:50:48] "GET / HTTP/1.1" 200 -

Now, let's install ngrok so that we can easily get a public URL and test.

$ unzip /path/to/ngrok.zip
$ ngrok

https://ff9dc197.ngrok.io -> localhost:5000

Open again the *.ngrok.io URL in your browser and it should still display Hello World!.

Last, open the settings of orgname/open-source-project GitHub project and add a webhook:

  • Payload URL: https://ff9dc197.ngrok.io/postreceive
  • Content type: application/json
  • Secret: This is a secret
  • Let me select individual events: Check Push and Pull Request

Et voila, each time a commit is pushed (or a pull request is created) on orgname/open-source-project our server will handle the GitHub webhook and trigger CircleCI build of orgname/worker-with-privileges project with the following parameters:

  • SLICER_REPO_NAME
  • SLICER_REPO_BRANCH
  • SLICER_REPO_TAG
  • SLICER_REPO_REVISION

thanks

This work was inspired from there projects:

license

It is covered by the Slicer License:

https://github.com/slicer-apidocs-builder/License.txt

About

A simple GitHub post-receive web hook handler able to trigger a CircleCI build.

Topics

Resources

License

Stars

Watchers

Forks