-1

Below I have shown my .gitlab-ci.yml file:

variables:
  timezone: "Europe/Vienna"

stages:
  - style
  - build

style:
  stage: style
  script:
  - sudo docker run --rm -v $PWD:/code omercnet/pycodestyle

build:
  stage: build
  script:
    blla blla
    - sudo docker exec ${CI_PROJECT_PATH_SLUG} /bin/bash -c "./install.sh"
    blla blla

Next, it is my install.sh script:

#!/bin/bash
blla blla 

echo -e "\nmx_download_url: https://dl.bintray.com/random" >> /etc/random-installer/setup.yml
sed -i s+old text+new text+g etc/random-installer/setup.yml

blla blla

How I can use the value of the variable timezone from the yml file in the new text in the bash script?

1 Answers1

0

timezone is visible as environment variable for the gitlab jobs, however install.sh scripts is running from another context - it's executed by docker. Docker itself has access to $timezone, however containers it's operating with don't.

To solve your problem you can explicitly pass it:

- sudo docker exec -e TIMEZONE=$timezone ${CI_PROJECT_PATH_SLUG} /bin/bash -c "./install.sh"

This will set environment variable $TIMEZONE for install.sh inside the container.

Ilia Kondrashov
  • 715
  • 2
  • 9
  • 14
  • So I need to set TIMEZONE as an env variable in my runner then associate it in this command with the timezone variable within the yml file? Did I understand it correctly? –  Oct 04 '20 at 09:30
  • `envrionment:` section in `.gitlab-ci.yml` is already defining environment variables for your jobs, that's why I used `$timezone` (lowercase) in my example. I put value from environment section (`$timezone`) into environment variable inside docker container (`$TIMEZONE`). After replacing `sudo docker exec ...` by the example I provided you will be already able to use `$TIMEZONE` inside `install.sh`, no extra changes are required. – Ilia Kondrashov Oct 04 '20 at 09:43