Ensure that Danger only runs on Merge Requests
Issue
We noticed a pipeline failures on a few projects related to Danger:
- https://gitlab.com/gitlab-org/build/CNG/-/pipelines/240849661/failures
- https://gitlab.com/gitlab-org/build/CNG/-/pipelines/240848136/failures
- https://gitlab.com/gitlab-org/omnibus-gitlab/-/pipelines/240956172/failures
In our Slack thread in #distribution, we eventually found this thread discussing the same error. It was shared that Danger should only run on merge requests, as it is a review tool. If it runs outside the context of a merge request (like on master
on a merge commit), weird behavior like this can be expected.
Next steps
We'll need to update all of our projects that use Danger and ensure that they are only run on Merge Requests.
Details
The jobs should be defined in such a way as to check for the existence of $DANGER_GITLAB_API_TOKEN
and $CI_MERGE_REQUEST_ID
. Note, this usage requires Merge Request Pipelines (detached) configured. This is not present on all of our projects.
This can be:
# rules:
rules:
- if: '$DANGER_GITLAB_API_TOKEN && $CI_MERGE_REQUEST_ID'
# only/except:
only:
variables:
- $DANGER_GITLAB_API_TOKEN
- $CI_MERGE_REQUEST_ID
Edited by Jason Plum