Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GitlabCI run pipeline on specific branch and manual

Tags:

gitlab-ci

So i am unable to specify this two things togather

build/deploy with these specific conditions.

From a specific branchb : develop And allow to run any branch from web run pipeline button.

Ive tried adding both conditions but this builds non develop branches

my_build:
  stage: build
  only: 
    - develop
    - web

If i remove web it works only on develop branch but im not allowed to run the job from web button

Has anyone achieved this before ?

like image 718
Illiax Avatar asked Aug 01 '18 22:08

Illiax


People also ask

How do you trigger a pipeline on a merge request?

Create a new merge request from a source branch with one or more commits. Push a new commit to the source branch for a merge request. Select Run pipeline from the Pipelines tab in a merge request.

What is a detached merge request pipeline?

If you want the pipeline to run jobs only on commits to a branch that is associated with a merge request, you can use pipelines for merge requests. In the UI, these pipelines are labeled as detached . Otherwise, these pipelines appear the same as other pipelines.

Can you have multiple pipelines in GitLab?

You can set up GitLab CI/CD across multiple projects, so that a pipeline in one project can trigger a downstream pipeline in another project. You can visualize the entire pipeline in one place, including all cross-project interdependencies.


1 Answers

You can do this with the rules clause, introduced in GitLab 12.3:

  rules:
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
      when: always
    - if: $CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH
      when: manual

$CI_DEFAULT_BRANCH is what you have set as the default branch in your GitLab repository settings.

See this example repo that a member of the GitLab team created.

like image 180
Jan Fabry Avatar answered Oct 14 '22 14:10

Jan Fabry