Search code examples
gitlab-cigitlab-ci.yml

Gitlab-ci transform only to rules with unknown syntax


I have to update the syntax on our .gitlab-ci.yml from only syntax to rules. I did the majority of the changes, but I cannot find information on the following syntax :

deploy-image:
  stage: deploy
  only:
    - stage@helloTeam/Expansion

helloTeam/Expansion is the name of our repository, but I don't know what the stage@ is for. And how to convert it with rules. Any idea ?


Solution

  • This is documented in only/except examples for job control.

    The @ symbol denotes the beginning of a ref’s repository path

    And one example of its usage:

    To execute jobs only for the parent repository and not forks:

    job:
      only:
        - branches@gitlab-org/gitlab
      except:
        - main@gitlab-org/gitlab
        - /^release/.*$/@gitlab-org/gitlab
    

    So, foo@bar/baz in only: means foo is a ref (branch name or special keyword) and bar/baz is a repository path.

    The following rules: could be used as an equivalent to this using the predefined variables CI_COMMIT_REF_NAME and CI_PROJECT_PATH:

    rules:
      - if: $CI_PROJECT_PATH == "bar/baz" && $CI_COMMIT_REF_NAME == "foo"