gitlab-ci-local icon indicating copy to clipboard operation
gitlab-ci-local copied to clipboard

Add support for protected variable

Open greenmaid opened this issue 2 years ago • 0 comments

Is your feature request related to a problem? Please describe. Currently I don't see any way to simulate behavior of protected variables, ie variables only available on specific refs

Describe the solution you'd like It would be great if some variables in variables.yml could be available only on given CI_COMMIT_REF_NAME. Gitlab makes difference between protected branches and protected tags, perhaps it is not needed be so specific.

  • For example there could be a new variable parameter (protected => boolean) and a cli parameter for protected refs definition

.gitlab-ci-local-variables.yml

global:
  PROTECTED_VAR:
    type: variable
    protected: true
    value: "Only on protected refs"

.gitlab-ci-yml

job:
   script:
      - echo $PROTECTED_VAR

and

$ gitlab-ci-local --protected-refs='*release*' --variable CI_COMMIT_REF_NAME=main gives:

echo $PROTECTED_VAR

$ gitlab-ci-local --protected-refs='*release*' --variable CI_COMMIT_REF_NAME=release_dev gives:

echo $PROTECTED_VAR
Only on protected refs

by default protected would set to false and --protected-refs to something like '(main|master)'

Describe alternatives you've considered I don't know how to simulate this behavior otherwise

greenmaid avatar Oct 06 '22 16:10 greenmaid