Push new branch to GitLab

What is the best practice for achieving this?

STAGE:
  stage: deploy
  image:
    name: bitnami/kubectl:1.26
    entrypoint: [""]
  script:
     ...
  rules:
    - changes:
      - .gitlab-ci.yml
    when: never
    - if: $CI_COMMIT_REF_NAME =~ /^release\/\d+\.\d+\.\d+$/

I have configured a GitlabCI job to deploy branches that follow the naming convention release/x.y.z. However, the job is not triggered when I push the branch for the first time. How can I configure the job to be triggered the first time I push the branch?

To configure the GitlabCI job to be triggered the first time you push the branch, you can modify the when condition in the job configuration. Update the when condition to include the manual option. Here’s the modified configuration:

STAGE:
  stage: deploy
  image:
    name: bitnami/kubectl:1.26
    entrypoint: [""]
  script:
     ...
  rules:
    - changes:
      - .gitlab-ci.yml
    when: manual | on_success
    - if: $CI_COMMIT_REF_NAME =~ /^release\/\d+\.\d+\.\d+$/

By adding manual to the when condition, the job will be triggered the first time you push the branch.