YasserL
YasserL

Reputation: 3

Running a pipeline on a protected branch in GitLab

We set up a containerized GitLab instance recently and we're trying to set up CI/CD pipelines to run on our repositories.

We have the runners set up and working, and as we created these repositories, we are owners and should have no problems running pipelines, which is the case when we try to run a pipeline on a non-protected branch. That's not the case however when it comes to protected branches, be it the (main) default branch or another branch we create with the protected tag.

Here is the content of the .gitlab-ci.yml file, with "protegee" being the newly created protected branch:

build_job:
    tags:
        - tests 
    before_script:
        - touch worked.txt
        - echo "hello there" > worked.txt
    script:
        - cat worked.txt 
        - echo "worked" >> worked.txt
        - cat worked.txt  
    rules:
    - if: $CI_COMMIT_BRANCH == "protegee"

We tried also

- if: $CI_COMMIT_REF_PROTECTED == "true"

but to no avail.

This is what the repository settings look like:

protected branches settings

And this is the runners config in settings:

group runners settings

The problem is that the pipeline doesn't run at all when the branch is protected, and displays this:

pipeline creation failed

and says "yaml invalid", when the same yaml works when we remove the "protected" status from the branch.

We've been reading the docs but found nothing so far that can help us.

Does anyone have an idea how on we can resolve this?

Upvotes: 0

Views: 229

Answers (0)

Related Questions