A concourse resource to check for new merge requests on GitLab and update the merge request status.
The provided Docker image is Alpine-based.
resource_types:
- name: merge-request
type: docker-image
source:
repository: samcontesse/gitlab-merge-request-resource
resources:
- name: merge-request
type: merge-request
source:
uri: https://gitlab.com/myname/myproject.git
private_token: XXX
uri
: (required) The location of the repository (required)private_token
: (required) Your GitLab user's private token (required, can be found in your profile settings)insecure
: When set totrue
, SSL verification is turned offskip_work_in_progress
: When set totrue
, merge requests mark as work in progress (WIP) will be skipped. Defaultfalse
skip_not_mergeable
: When set totrue
, merge requests not marked as mergeable will be skipped. Defaultfalse
skip_trigger_comment
: When set totrue
, the resource will not look up for[trigger ci]
merge request comments to manually trigger builds. Defaultfalse
concourse_url
: When set, this url will be used to overrideATC_EXTERNAL_URL
during commit status updates.pipeline_name
(string): When set, this url will be used to overrideBUILD_PIPELINE_NAME
during commit status updates.labels
(string[]): Filter merge requests by label[]
paths
(string[]): Include merge request if one of the modified file matches a path pattern (glob). Default: include all.ignore_paths
(string[]): Exclude merge request if one of the modified files matches a path pattern (glob). Default: exclude none.target_branch
(string): Filter merge requests by target_branch. Default is empty string.source_branch
(string): Filter merge requests by source_branch. Default is empty string.sort
(string): Merge requests sorting order, eitherasc
(default) ordesc
to reverse.ssh_keys
(string[]): When set to a non-empty array, an ssh-agent will be started and the specified keys will be added to it. This is only relevant for submodules with an ssh URL and passphrase encrypted keys are not supported.recursive
: When set totrue
, will pull submodules by issuing agit submodule update --init --recursive
. Note that if your submodules are hosted on the same server, be sure to use a relative path to avoid ssh/https protocol clashing (as the MR is fetched via https, this resource would have no way to authenticate a git+ssh connection).
Checks if there are new merge requests or merge requests with new commits.
git clone
s the source branch of the respective merge request.
If you need to retrieve any information about the merge request in your tasks, the script writes the raw API response of the
get single merge request call to .git/merge-request.json
.
The name of the source branch is extracted to .git/merge-request-source-branch
for convenience.
Updates the merge request's merge_status
which displays nicely in the GitLab UI and allows to only merge changes if they pass the test.
repository
: The path of the repository of the merge request's source branch (required)status
: The new status of the merge request (required, can be eitherpending
,running
,success
,failed
, orcanceled
)labels
(string[]): The labels you want to add to your merge requestcomment
: Add a comment for MR. Could be an object withtext
/file
fields. If just thefile
ortext
is specified it is used to populate the field, if bothfile
andtext
are specified then the file is substituted in to replace $FILE_CONTENT in the text.
jobs:
- name: sample-merge-request
plan:
- get: merge-request
trigger: true
- put: merge-request
params:
repository: merge-request
status: running
- task: unit-test
file: merge-request/ci/tasks/unit-test.yml
on_failure:
put: merge-request
params:
repository: merge-request
status: failed
on_success:
put: merge-request
params:
repository: merge-request
status: success
labels: ['unit-test', 'stage']
comment:
file: out/commt.txt
text: |
Add new comment.
$FILE_CONTENT