0

on gitlab.com the creation of an issue together with a new branch and a merge request directly triggers CI pipeline start. This is unexpected to me, because the new branch contains not a single change. Why is the pipeline triggered?

Best, Lars

reschifl
  • 377
  • 4
  • 13

1 Answers1

1

As stated in the GitLab Pipeline documentation, "each commit or push triggers your CI pipeline". Since new git branches are created on a remote repository via push, the pipeline is triggered when a new branch is created.

Rationale:

On first glance, this behavior seems superfluous, but GitLab allows you to run different jobs depending on the current branch of the repository; for example, you could run your "deploy" job only on the master branch. Therefore from GitLab's perspective it makes sense to execute the Pipeline each time a new branch is created.

More information is available here: https://docs.gitlab.com/ce/ci/yaml/README.html#only-and-except-simplified

Introduced with GitLab 11.4, this behaviour is now explained:

If you are pushing a new branch or a new tag to GitLab, the policy always evaluates to true and GitLab will create a job. This feature is not connected with merge requests yet, and because GitLab is creating pipelines before an user can create a merge request we don't know a target branch at this point.

Without a target branch, it is not possible to know what the common ancestor is, thus we always create a job in that case. This feature works best for stable branches like master because in that case GitLab uses the previous commit that is present in a branch to compare against the latest SHA that was pushed.

Source: https://docs.gitlab.com/ee/ci/yaml/#only-changes

Community
  • 1
  • 1
Philipp Ludwig
  • 3,758
  • 3
  • 30
  • 48
  • Thank you for these hints. Is there a way to prevent the start only for branch creation to not waste pipeline quota? – reschifl Oct 18 '18 at 14:57
  • Not as I know. But you could enable the pipeline cache to reuse previous results, see here: https://docs.gitlab.com/ce/ci/caching/ – Philipp Ludwig Oct 19 '18 at 09:28
  • @reschifl GitLab 11.4 was released today, with updated documentation regarding this behaviour; the rationale behind it is now explained. – Philipp Ludwig Oct 23 '18 at 08:06