Skip to content

Triggering builds from webhooks

Description

Currently GitLab can trigger builds from external tools like curl. But there is no way to trigger builds with webhook from another GitLab project. Executing webhook like /projects/:id/trigger/builds?token=TOKEN&ref=master results in such message from server:

400 No builds created

This can be emulated with curl:

curl \
    --request POST \
    --header 'Content-type: application/json' \
    --data '{"ref": "refs/heads/other-branch"}' \
    'http://gitlab.example.com/api/v3/projects/:id/trigger/builds?token=TOKEN&ref=master'

Server responds to this request with the following text:

{"message":"No builds created"}

Problem is the ref from request body takes precedence of the ref from query string. System tries to trigger build for nonexistent branch refs/heads/other-branch instead of master. This is the feature of the Grape framework used to build GitLab api.

Proposal

Propose to add optional ref parameter into the api url:

/projects/:id/ref/:ref/trigger/builds?token=TOKEN

This will lead that the ref in the url will have precedence of the ref inside request body.

This solution provides compability with current api urls.

Links / references

Merge request will be attached to this issue.