AndyP
AndyP

Reputation: 607

How to run build stage in gitlab pipeline on branch creation?

I have a gitlab pipeline which has two stages as shown below:

Below is my current .gitlab-ci.yml:

  stages:
    - build
    - push

  build:
    image: docker.repo.test.data/stuff/something:latest
    variables:
      LEGACY_VERSION: 10000
    before_script:
      - export CI_PIPE_ID=`expr $CI_PIPE_ID + $OLDER_VERSION`
    script:
      - echo "Building Project"
      - ls -lrth
      - ./build-project

  push:
    stage: push
    image: docker.repo.test.data/stuff/something:latest
    only:
        - master
    script:
      - some stuff here

In my build stage I try to build my project and in push stage I try to push it. My push stage only happens if any PR gets merged to master branch or any commit gets added to master branch as I am using only there.

Problem Statement

Now I want to run my build stage for below things as well:

Is this possible to do by any chance? Right now whenever I create a branch from master it doesn't run build stage.

Upvotes: 0

Views: 1955

Answers (1)

Igor Redka
Igor Redka

Reputation: 1

probably you can create if rules like this

if: $CI_COMMIT_BRANCH == /branch name/ && $CI_COMMIT_BEFORE_SHA == "0000000000000000000000000000000000000000"

According to the docs https://docs.gitlab.com/ee/ci/variables/predefined_variables.html

The previous latest commit present on a branch or tag. Is always 0000000000000000000000000000000000000000 for merge request pipelines, the first commit in pipelines for branches or tags, or when manually running a pipeline.

Upvotes: 0

Related Questions