Skip to content

CI Pipelines run for every commit on every branch

Summary

GitLab Pipeline is triggered for every commit made to every other branch instead of only running it when "main" branch changes. Below is the .gitlab-ci.yml

# Build the main branch
build-staging:
    stage: build
    image: akashpavate58/msbot-build-engine:latest
    script:
        - npm install
        - mkdir build-artifact && zip -r build-artifact/app.zip .
    cache:
        key: $CI_COMMIT_REF_SLUG-$CI_COMMIT_SHORT_SHA
        paths:
            - build-artifact/
    rules:
        - if: $CI_COMMIT_REF_NAME == "main"

# Deploy the main branch to staging environment  
deploy-staging:
    stage: deploy
    image: mcr.microsoft.com/azure-cli:latest
    dependencies:
        - build-staging
    cache:
        key: $CI_COMMIT_REF_SLUG-$CI_COMMIT_SHORT_SHA
        paths:
            - build-artifact/
        policy: pull
    before_script: 
        - az login --service-principal --username="${CI_APP_ID}" --password="${CI_APP_SECRET}" --tenant="${CI_TENANT_ID}"
    script:
        - az webapp deployment source config-zip -n ${AZ_APP_NAME_STAGING} -g ${AZ_RG_NAME_STAGING} --src build-artifact/app.zip
    after_script:
        - az logout
    rules:
        - if: $CI_COMMIT_REF_NAME == "main"

Steps to reproduce

  1. Create a GitLab.com project and add a .gitlab-ci.yml to it that will run a pipeline only for changes to default branch
  2. Invite new users by email - Make sure these users sign up for GitLab and do not perform credit card validation
  3. Login as one of the new user and create a new branch from main branch.
  4. Make a new commit to the new branch
  5. You should now see an entry in the CI/CD > Pipelines with status failed for the new branch

Example Project

What is the current bug behavior?

  1. GitLab creates adds a job to the pipeline for every commit on any branch made by a new GitLab user (Who has not performed credit card validation)

What is the expected correct behavior?

  1. There should be job created for every commit on every branch unless specified in .gitlab-ci.yml

Relevant logs and/or screenshots

image

Even Merge Request completed by new gitlab users don't run successfully. Refer image below. image

Output of checks

Results of GitLab environment info

Expand for output related to GitLab environment info

(For installations with omnibus-gitlab package run and paste the output of:
`sudo gitlab-rake gitlab:env:info`)

(For installations from source run and paste the output of:
`sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production`)

Results of GitLab application Check

Expand for output related to the GitLab application check

(For installations with omnibus-gitlab package run and paste the output of: sudo gitlab-rake gitlab:check SANITIZE=true)

(For installations from source run and paste the output of: sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production SANITIZE=true)

(we will only investigate if the tests are passing)

Possible fixes

Edited by Akash Pavate