13

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 ?

4
  • The question statement is not that much clear. Do you want to run your pipeline manually via web interface for a particular branch? Aug 5, 2018 at 4:43
  • I want to be able to run pipeline manually for any branch. And one specific branch (develop) automatically. (Sorry if i wasnt clearer)
    – Illiax
    Aug 6, 2018 at 16:06
  • Then Answer provided by@Thomas is the solution. Aug 7, 2018 at 4:13
  • @RuwankaMadhushan it didnt work for me, but i get to do something useful from his answers. Thanks all
    – Illiax
    Aug 15, 2018 at 21:34

3 Answers 3

25

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.

1
  • Can this simplified by omiting if: $CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH and just use - when: manual?
    – KargWare
    Nov 9, 2023 at 16:55
11

I understand: You want to run the builds on branch develop automatically but in branch web manually?

You can't do this in one build, but you can use two builds for it:

my_build:develop
  stage: build
  only:
    - develop

my_build:web
  stage: build
  only:
    - web
  when: manual
3
  • does ''when: manual'' exists ? this is sort of an answer, but i can work with this. There is no web branch, web was the keyword (iirc) that allows manual run of the pipeline (from the web)
    – Illiax
    Aug 6, 2018 at 15:50
  • Invalid YAML. Do you mean my_build_develop: and my_build_web: rather than my_build:develop ? Aug 27, 2020 at 8:27
  • Yes, you're right. You also can put the names into quotes. Aug 27, 2020 at 14:00
0

use [CI RUN] in your commmit message. Ex: git commit -m "fixed merge conflicts [CI RUN]"

1
  • Not scalable when we want to force some code quality checks. People will skip it
    – nimi0112
    Mar 24, 2023 at 18:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.