MasterAler
MasterAler

Reputation: 1653

Gitlab CI script: exclude branches

I'm trying to improve the project building script, described in YML-file, the improvement itself seems quite trivial, but the idea of accidentally ruining the auto-builds scares me a bit.

Right now there are several branches, version tags and other stuff in the project.

A development branch, not built by the runners would be of use, because copying a huge project somehow between virtual machines to test the build on different platforms is not convenient at all. So, I want to exclude from builds some "prj-dev" branch.

And there we have:

stages:
 - build
 - linuxbuild
job:
 tags:
 - win2008build
 stage: build
 script:
  # something complex

job1:
 tags:
 - linux
 stage: linuxbuild
 script:
  # something else complex

I googled and found a solution like:

stages:
 - build
 - linuxbuild
job:
 tags:
 - win2008build 
 branches:
  except:
    - *dev-only

But it seems that our pipelines are quite different, the tags are not git tags, they are pipeline tags. So, I'm considering rather to use a config like:

stages:
 - build
 - linuxbuild
job:
 tags:
 - win2008build 
 except:
   branches:
    - *dev-only

...which would mean "build as usual, but not my branch". There are complications in trying it both ways, I'm pretty sure someone should know the recipe for sure.

So, if you please, -- how do I exclude my dev branch without changing the pipelines, config only? Is it possible at all?

Upvotes: 22

Views: 31904

Answers (2)

ashraf minhaj
ashraf minhaj

Reputation: 1193

With only and except, you can do this. I wanted this job to run for all feature branches like 'feat' and 'feat/feat_name', but not for the 'main' branch -

build_docker_img:
  stage: build_img
  image: docker:latest
  services:
    - docker:dind
  script:
    - cd app
    - docker build -t $DOCKER_IMG_TAG .
  only:
    - "*/*"
    - "*"
  except:
    - main

Upvotes: 0

Thomas Löffler
Thomas Löffler

Reputation: 6174

All you need to do is use except in the gitlab-ci.yml file and add your branches directly below like this:

mybuild:
    stage: test
    image: somedockerimage
    script:
        - some script running
    except:
        - branch-name

This is working on my project without problems.

Upvotes: 47

Related Questions