Allow setting variable to a contents of a file

Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.

  • Close this issue

I need to be able to define image: for the job based on the contents of a file from git repository. It is already possible to use variables for the image:, but it is not possible to define a variable to be equal to the contents of a file.

For example, if I have config/version.txt file in my repo, then I could write the following in gitlab-ci.yml:

variables:
  img_ver:
    file_contents: "config/version.txt"

image: mydockerhub/myimage:version_$img_ver

Other people on the internet are also interested about such feature:

  • https://stackoverflow.com/questions/49026724/set-gitlab-ci-yml-variable-via-bash-command
  • https://forum.gitlab.com/t/how-to-use-value-from-version-file-in-repository-as-image-variable/26199
Edited Aug 13, 2025 by 🤖 GitLab Bot 🤖
Assignee Loading
Time tracking Loading