0

Given the following very simple .gitlab-ci.yml pipeline:

---
variables:
  KEYCLOAK_VERSION: 20.0.1 # this should be populated from reading a file from the repo...

stages:
  - test

build:
  stage: test
  script:
    - echo "$KEYCLOAK_VERSION"

As you might see, this simply outputs the value of KEYCLOAK_VERSION defined in the variables section.

Now, the Git repository contains a env.properties file with KEYCLOAK_VERSION=20.0.1 as content. How would I read the variable from that file and use it in the GitLab pipeline?

The documentation mentions import but this seems to be using YAML files.

1 Answer 1

2

To read variables from a file you can use the source or . command.

script:
  - source env.properties
  - echo $KEYCLOAK_VERSION

Attention: One reason why you might not want to do it this way is because whatever is in env.properties will be run in your shell, such as rm -rf /, which could be very dangerous.

Maybe you can take a look here for some other solutions.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.