Name: bitrise-webhooks
Owner: Bitrise
Description: Bitrise Webhooks processor
Created: 2016-02-03 15:24:26.0
Updated: 2018-03-16 11:52:58.0
Pushed: 2018-01-17 09:39:50.0
Homepage: null
Size: 611
Language: Go
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
Bitrise Webhooks processor.
Transforms various webhooks (GitHub, Bitbucket, Slack, …) to bitrise.io's Build Trigger API format, and calls it to start a build.
Feel free to add your own webhook transform provider to this project! For more information check the How to add support for a new Provider section.
If the (commit) message includes [skip ci]
or [ci skip]
no build will be triggered.
/h/github/BITRISE-APP-SLUG/BITRISE-APP-API-TOKEN
/h/bitbucket-v2/BITRISE-APP-SLUG/BITRISE-APP-API-TOKEN
/h/bitbucket-server/BITRISE-APP-SLUG/BITRISE-APP-API-TOKEN
/h/slack/BITRISE-APP-SLUG/BITRISE-APP-API-TOKEN
/h/visualstudio/BITRISE-APP-SLUG/BITRISE-APP-API-TOKEN
/h/gitlab/BITRISE-APP-SLUG/BITRISE-APP-API-TOKEN
/h/gogs/BITRISE-APP-SLUG/BITRISE-APP-API-TOKEN
/h/deveo/BITRISE-APP-SLUG/BITRISE-APP-API-TOKEN
/h/assembla/BITRISE-APP-SLUG/BITRISE-APP-API-TOKEN
Service independent:
/h/passthrough/BITRISE-APP-SLUG/BITRISE-APP-API-TOKEN
All you have to do is register your bitrise-webhooks
URL for
a GitHub repository.
Settings
of the repositoryWebhooks
Add webhook
bitrise-webhooks
URL (.../h/github/BITRISE-APP-SLUG/BITRISE-APP-API-TOKEN
) in the Payload URL
fieldbitrise-webhooks
supports the Push
and Pull Request
events,
every other webhook (triggered by another event) will be ignored.Add webhook
That's all! The next time you push code, push a new tag or create/update a pull request a build will be triggered (if you have Trigger mapping defined for the event(s) on Bitrise).
All you have to do is register your bitrise-webhooks
URL for
a Bitbucket repository.
Settings
of the repositoryWebhooks
Add webhook
bitrise-webhooks
URL (.../h/bitbucket-v2/BITRISE-APP-SLUG/BITRISE-APP-API-TOKEN
) in the URL
fieldChoose from a full list of triggers
and the following properties:Save
That's all! The next time you push code, push a new tag or create/update a pull request a build will be triggered (if you have Trigger mapping defined for the event(s) on Bitrise).
All you have to do is register your bitrise-webhooks
URL for
a Bitbucket Server repository.
Settings
of the repositoryWebhooks
Create webhook
bitrise-webhooks
URL (.../h/bitbucket-server/BITRISE-APP-SLUG/BITRISE-APP-API-TOKEN
) in the URL
fieldSave
That's all! The next time you push code, push a new tag or create a pull request a build will be triggered (if you have Trigger mapping defined for the event(s) on Bitrise). Please note that Bitbucket Server doesn't send any notifications when new commits are pushed to an existing PR, so no builds will be triggered by these events.
All you have to do is register your bitrise-webhooks
URL for
a GitLab project.
Settings
of the projectWeb Hooks
bitrise-webhooks
URL (.../h/gitlab/BITRISE-APP-SLUG/BITRISE-APP-API-TOKEN
) in the URL
fieldPush events
Tag push events
Merge Request events
Add Web Hook
That's all! The next time you push code, push a new tag or create/update a merge request a build will be triggered (if you have Trigger mapping defined for the event(s) on Bitrise).
All you have to do is register your bitrise-webhooks
URL as a Webhook in your Gogs repository.
Settings
of the projectWebhooks
, Add Webhook
, then Gogs
.bitrise-webhooks
URL (.../h/gogs/BITRISE-APP-SLUG/BITRISE-APP-API-TOKEN
) in the Payload URL
field.Content Type
to application/json
.Just the push event
That's all! The next time you push code a build will be triggered (if you have Trigger mapping defined for the event(s) on Bitrise).
All you have to do is register your bitrise-webhooks
URL for
a visualstudio.com project as a Service Hooks
integration.
You can find an official guide on visualstudio.com 's documentations site.
A short step-by-step guide:
Service Hooks
Web Hooks
optionCode pushed
event as the TriggerFilters
section select the Repository
you want to integrateNext
Action
setup form specify the bitrise-webhooks
URL (.../h/visualstudio/BITRISE-APP-SLUG/BITRISE-APP-API-TOKEN
) in the URL
fieldFinish
That's all! The next time you push code or push a new tag a build will be triggered (if you have Trigger mapping defined for the event(s) on Bitrise).
All you have to do is register your bitrise-webhooks
URL for
a Deveo repository.
Hooks
of the projectwebhook
bitrise-webhooks
URL (.../h/deveo/BITRISE-APP-SLUG/BITRISE-APP-API-TOKEN
) in the Url
fieldjson
in the Content type
fieldSave hook
That's all! The next time you push code or push a new tag a build will be triggered (if you have Trigger mapping defined for the event(s) on Bitrise).
Follow these steps to add your bitrise-webhooks
URL to your Assembla space.
Webhooks
section of the spaceCreate New Webhook
Title
to BitRise Webhook
bitrise-webhooks
URL (.../h/assembla/BITRISE-APP-SLUG/BITRISE-APP-API-TOKEN
) in the External url
fieldapplication/json
in the Content type
fieldContent
:sembla": {"space": "%{space}", "action": "%{action}", "object": "%{object}"}, "message": {"title": "%{title}", "body": "%{body}", "author": "%{author}"}, "git": {"repository_suffix": "%{repository_suffix}", "repository_url": "%{repository_url}", "branch": "%{branch}", "commit_id": "%{commit_id}"}}
Code commits
and/or Git Push
in the Post updates about:
sectionAdd
That's all! The next time you push code a build will be triggered (if you have Trigger mapping defined for the event(s) on Bitrise).
You can register the bitrise-webhooks
URL (.../h/slack/BITRISE-APP-SLUG/BITRISE-APP-API-TOKEN
) as either
an Outgoing Webhook or
as a slash command for your Slack team.
Once the URL is registered check the usage section below for all the accepted and required parameters you can define in the message, and for a couple of examples.
Your message have to be in the format: key:value|key:value|...
,
where the supported keys
are:
At least one of these two parameters are required:
b
or branch
- example: branch: master
w
or workflow
- example: workflow: primary
Other, optional parameters:
t
or tag
- example: branch: master|tag: v1.0
c
or commit
- example: workflow: primary|commit: eee55509f16e7715bdb43308bb55e8736da4e21e
m
or message
- example: branch: master|message: ship it!!
NOTE: at least either branch
or workflow
have to be specified, and of course
you can specify both if you want to. You're free to specify any number of optional parameters.
You can also send environment variables that will be available in your workflow with the format: env[KEY1]:value1|ENV[KEY2]:value2
An example with all parameters included: workflow: primary|b: master|tag: v1.0|commit:eee55509f16e7715bdb43308bb55e8736da4e21e|m: start my build!|ENV[DEVICE_NAME]:iPhone 6S|ENV[DEVICE_UDID]:82667b4079914d4aabed9c216620da5dedab630a
Simply register or use the .../h/passthrough/BITRISE-APP-SLUG/BITRISE-APP-API-TOKEN
url.
Every request received on the passthrough
endpoint will trigger a build, no filtering is done or supported!.
The only limit is that neither the Headers nor the Body can be larger than 10kb.
The headers will be passed to the build in JSON serialized form, as the value of BITRISE_WEBHOOK_PASSTHROUGH_HEADERS
.
Note: headers are key value maps where the value is an array or strings, not just a single string value!
Example:
"Content-Type": [
"application/json"
],
"Some-Custom-Header-List": [
"first-value",
"second-value"
]
The body will be passed to the build as-it-is (in string/text form), as the value of BITRISE_WEBHOOK_PASSTHROUGH_BODY
.
Demo: run the server locally (e.g. with bitrise run start
) and call the .../h/passthrough/...
endpoint with curl
:
-X POST --data 'just a text body' -H 'Example-Header: example header value' 'http://localhost:4000/h/passthrough/BITRISE-APP-SLUG/BITRISE-APP-API-TOKEN'
by default the server will print what and where it would send (debug mode), so you should see this in the server's log:
/09/10 16:30:18 ===> Triggering Build: (url:https://app.bitrise.io/app/BITRISE-APP-SLUG/build/start.json)
/09/10 16:30:18 ====> JSON body: {"build_params":{"branch":"master","environments":[{"mapped_to":"BITRISE_WEBHOOK_PASSTHROUGH_HEADERS","value":"{\"Accept\":[\"*/*\"],\"Accept-Encoding\":[\"gzip\"],\"Content-Length\":[\"16\"],\"Content-Type\":[\"application/x-www-form-urlencoded\"],\"Example-Header\":[\"example header value\"],\"User-Agent\":[\"curl/7.54.0\"],\"X-Forwarded-For\":[\"::1\"]}","is_expand":false},{"mapped_to":"BITRISE_WEBHOOK_PASSTHROUGH_BODY","value":"just a text body","is_expand":false}]},"triggered_by":"webhook"}
1.6
or newer required!git clone
the project into your GOPATH: git clone your-fork.url $GOPATH/src/github.com/bitrise-io/bitrise-webhooks
cd $GOPATH/src/github.com/bitrise-io/bitrise-webhooks
Start the server:
Go
code go install
bitrise-webhooks -port=4000
Alternatively, with bitrise CLI:
bitrise run start
By default the server will be started in Development Mode. This means that it won't send requests, it'll only print the request in the logs.
You can pass the -send-request-to
flag, or set the SEND_REQUEST_TO
environment
variable to enable sending the requests to the specified URL (every request
will be posted to the exact URL you specify).
You can switch the server into Production mode by defining the
environment variable: RACK_ENV=production
. In production mode
the server will send requests to bitrise.io,
unless you specify a send-request-to parameter.
bitrise-webhooks
serverhttp(s)://YOUR-BITRISE-WEBHOOKS.DOMAIN/h/SERVICE/BITRISE-APP-SLUG/BITRISE-APP-API-TOKEN
You can use http://requestb.in to debug/check a service's webhook format.
If you have a Heroku account you can quickly create & start your own RequestBin server for free, just follow the guide on RequestBin's GitHub page.
Create a RequestBin, and register the provided URL as the Webhook URL on the service you want to test. Once the service triggers a webhook you'll see the webhook data on RequestBin.
You can pass the -send-request-to
option (or SEND_REQUEST_TO
env var) to this server to
send all the request to the specified URL (e.g. to RequestBin), instead of sending
it to bitrise.io.
git clone
the code - either the official code or your own forkcd
into the source code directoryheroku create
heroku config:set SEND_REQUEST_TO=http://request-bin-or-similar-service.com/abc123
heroku config:set RACK_ENV=production
SEND_REQUEST_TO
config is no longer set. While SEND_REQUEST_TO
is set
every request will be sent to the specified URL, it doesn't matter whether you're in Development
or Production mode.
You can simply set an empty value for SEND_REQUEST_TO
to disable it: heroku config:set SEND_REQUEST_TO=""
git push heroku master
heroku ps:scale web=1
Alternatively you can use this Heroku deploy button, if you prefer the web UI over the heroku CLI:
Done. Your Bitrise Webhooks server is now running on Heroku.
You can open it with heroku open
- opening the root URL of the server
should present a JSON data, including the server's version
,
the current time
, the server's environment_mode
and a welcome message
.
Implement your webhook provider support code into ./service/hook/theprovider
.
Unit tests are required if you want your code to be merged into the
main bitrise-wekhooks
repository!
Once the implementation is ready add it to the selectProvider
function,
to the supportedProviders
list, in the service/hook/endpoint.go
file.
For an example you should check the service/hook/github
(single webhook triggers
only one build)
or the service/hook/bitbucketv2
(a single webhook might trigger multiple builds)
provider implementation.
service/hook/github
for an example if a single webhook
can be transformed into a single build trigger, or service/hook/bitbucketv2
if a single webhook might trigger multiple buildsservice/hook
, following the naming pattern of existing providers (and Go package naming conventions)..._test.go
)TransformRequest
method, with checks for the required inputs (headers, event type, etc.).transformCodePushEvent
function in the service/hook/github
service as for an example_test.go
file,
without an actual test implementation.TransformRequest
function,
test & implement that toogithub
and bitbucketv2
services.bitrise run test
go test ./...
github
in this example): go test ./service/hook/github/...
service/hook/endpoint.go
supportedProviders
map/h/PROVIDER-ID/BITRISE-APP-SLUG/BITRISE-APP-API-TOKEN
bitrise-webhooks
executable on your serverDone! You can now test your provider on a server (check the Deployment section), and you can create a Pull Request, to have it merged with the official bitrise.io webhook processor.
Once you have a working Provider you can optionally define response transformers too. With this you can define the exact response JSON data, and the HTTP status code, both for success and for error responses.
If you don't define a response Transformer the default response provider
will be used (service/hook/default_reponse_provider.go
).
To define your own Response Provider/Transform functions you just have to
implement the functions of ResponseTransformer
(service/hook/common/common.go
).
If your Provider implements these functions it'll be used for generating the response. You have to implement every function defined in the interface, or your Provider won't be considered as an implementation of the interface and the default response provider will be used instead.
Response is always in JSON format.
If provider declares the response transformers it'll be used, and the provider is responsible for generating the response JSON.
If it doesn't provide the response transformer functions then the default response provider will be used.
The default response provider generates the following responses:
{"error": "..."}
response
will be generated (with HTTP code 400
).{"message": "..."}
response
will be generated (with HTTP status code 200
)."success_responses": []
and "failed_responses": []
JSON arrays"errors": []
JSON array (if any)200
. This is to prevent services to “disable” the Webhook,
as most of the git hosting services auto-disable webhooks if too many / too frequent non 2xx
responses received.2xx
(success) code,
but instead it'll return a 400
error with as much details in the response about the
error as the server can determine.201
{"did_not_wait_for_trigger_response": true}
with
a HTTP 200
code.Gogs
supportSlack
commandsAssembla
supportBitbucket Server
support