This is a simple Node.js + express API written in TypeScript, that mainly acts as a workaround to enable Danger to be run on GitLab CI runners.
GitLab CI runners currently don't have an environment variable, that allows Danger to determine the ID of the merge request. A proposal to enable pipelines for merge requests is currently discussed: https://gitlab.com/gitlab-org/gitlab-ce/issues/23902. For the meantime, this application can be used as a workaround.
The principle is quite simple: You run this application on a publicly available server and register the endpoint as a webhook in your GitLab repository. The webhook should only fire for merge requests! Additionally, you create a trigger in the same GitLab repository. Now, when you create a new merge request, GitLab will send a JSON object to your endpoint, the application will extract the project id and the merge request id and send a request to GitLab to trigger a new build with additional parameters.
The additional parameter (that Danger is looking for) is CI_MERGE_REQUEST_ID
.
- Create a integration (webhook) in your GitLab repository, targeting
<your-FQDN>.com:3000/v1/triggerBuildOnMR
. Make sure to enter aSecret Token
, you will need it in step XXXX - Create a new trigger for the same GitLab repository.
- Pull my image from Docker Hub: ffittschen/gitlab-ci-trigger
docker pull ffittschen/gitlab-ci-trigger:latest
- Run the docker image:
docker run -p 3000:3000 -e X-GITLAB-TOKEN='YOUR-SECRET-TOKEN' -e GitlabTriggerToken='YOUR-TRIGGER-TOKEN' ffittschen/gitlab-ci-trigger:latest
Note: Replace YOUR-SECRET-TOKEN
and YOUR-TRIGGER-TOKEN
in the command above with your tokens from steps 1 and 2!
- Follow steps 1. and 2. from the Usage > Docker section
- Set the tokens as environment variables, e.g.
export X-GITLAB-TOKEN=YOUR-SECRET-TOKEN
,export GitlabTriggerToken=YOUR-TRIGGER-TOKEN
- Clone this repository:
git clone https://github.com/ffittschen/gitlab-ci-trigger.git
- Install all dependencies:
yarn install
- Start the server:
yarn start
PRs are welcome!
MIT © Florian Fittschen