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

独自空忆成欢 提交于 2021-01-29 05:36:42

问题


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:

  • If someone creates a branch from master which starts with release-xxx name then I want to run only build stage.
  • If someone creates a branch from a particular commit which starts with release-xxx name then I want to run only build stage.
  • And for all other cases it should run build stage just like it is doing currently in my original .gitlab-ci.yml file.

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

来源:https://stackoverflow.com/questions/65604509/how-to-run-build-stage-in-gitlab-pipeline-on-branch-creation

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!