Gitlab-ci transform only to rules with unknown synthax

54 Views Asked by At

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

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 ?

2

There are 2 best solutions below

1
sytech On BEST ANSWER

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"
0
Arctick On

Ok I found that target the branch stage on non forked repository.

More details about the only:refs / except:refs keywords can be found here. And for the refs possible values/inputs, check this link.

So, the equivalent with rules is :

  rules:
    - if: '$CI_PROJECT_NAMESPACE == "helloTeam" && $CI_COMMIT_BRANCH == "stage"'

Curious if it's possible to target the whole name, helloTeam/Expansion instead of just helloTeam.