firecow / gitlab-ci-local

Tired of pushing to test your .gitlab-ci.yml?
MIT License
2.03k stars 115 forks source link

dotenv variables are not loaded for `service` definitions #1196

Closed PigeonF closed 2 months ago

PigeonF commented 2 months ago

Minimal .gitlab-ci.yml illustrating the issue

---
build-image-ref:
  stage: build
  needs: []
  script:
    - echo "SERVICE_IMAGE_REF=docker.io/library/redis" >> build.env
    - echo "SERVICE_IMAGE_ALIAS=redis" >> build.env
  artifacts:
    reports: { dotenv: build.env }

use-service-ref:
  stage: deploy
  needs: [build-image-ref]
  services:
    - name: $SERVICE_IMAGE_REF
      alias: $SERVICE_IMAGE_ALIAS
  image: docker.io/tutum/dnsutils
  script:
    - host $SERVICE_IMAGE_ALIAS

Expected behavior The variable should be resolved, same as for image.

Host information gitlab-ci-local 4.47.0

Additional context I have added a test and a "solution" in https://github.com/PigeonF/gitlab-ci-local/tree/dotenv-in-service, but I am not well versed in typescript and the solution feels quite hacky, since the dotenv variables are not available in the constructor. If you want to, I can submit the changes as a PR, but I feel someone more experienced should think of a more robust solution instead.