Search code examples
variablesgitlabyamlgitlab-cipipeline

Run GitLab CI/CD pipeline with global variables in YAML files


I have a GitLab repository. It has a pipeline with multiple stages. The stages deploy everything I need from simple YAML files. I want to be able to use variables in those YAML files that would be the same across all stages.

For example, if I have:

something:
    name: "My component"
    version: 1.0

I want to use a variable instead of 1.0 across all stages. For example,

something:
    name: "My component"
    version: VERSION_VARIABLE

I heard that simple YAML files don't have variables the usual way, so what workaround could I make to use version as one value across all deployments?

Maybe the version value will be stored in Pipeline variables or repository's environment variables, but the question is how to use them in simple YAML files from which different components get deployed?


Solution

  • something:
        name: "My component"
        version: ${VERSION_VARIABLE}
    

    This did the trick!