0

How should I set up my .gitlab-ci.yml manifest to run builds ONLY on:

  • Merge Request;

  • Push to branch with opened merge request from it (I mean when the merge request from branch Y to branch X is already opened and some new changes are pushed to branch Y);

  • Push to master;

I've tried to solve it with a setting like this:

  job:
    only:
    - triggers
    - /merge-requests/
    - master
    except:
    - branches

Regarding on the documentation here: https://docs.gitlab.com/ce/ci/yaml/README.html#only-and-except-simplified

Suddenly the error occurred on my MR page:

Could not connect to the CI server. Please check your settings and try again.

When I removed only/except restrictions from my manifest, the error was gone.

What am I doing wrong here?

My Gitlab version is: GitLab Community Edition 10.8.1

zinovyev
  • 2,084
  • 1
  • 22
  • 32

1 Answers1

1

You want to run a job only on:

  1. merge request: I don't understand what you want here

  2. Push to branch with opened merge request from it: you have to set a special job that call the Gitlab API to control that the current branch has a MR

A job executed only on new pushed branch:
  image: alpine:latest
  script:
  - # <-- add here the script that call Gitlab API
  only:
  - branches
  1. Push to master:
A job executed only on master:
  image: alpine:latest
  script:
  - echo "Hello world!"
  only:
  - master
Ekans
  • 997
  • 1
  • 8
  • 16
  • 1. I mean I need a job that will be executed on specific branch only if a MR from the specific branch exists to master; 2. So, do you want to say, that I need to create some extra utility jobs and re-request Gitlab API with curl when the job is triggered to achieve this behaviour? – zinovyev May 28 '18 at 09:43
  • I have a similar use case: I want to check for each commit if a MR exists if not create it. To solve this I have a job executed on each feature branch doing the check/creation. Here is an [example](https://gist.github.com/plajjan/42592665afd5ae045ee36220e19919aa#file-open-mr-sh) of a script of this type – Ekans May 28 '18 at 10:16
  • As far as I know there is no condition saying "run this job only if the current branch has a MR" – Ekans May 28 '18 at 10:19