Pass Environments from a job to another

Hi, nice to meet you. I need help with gitlab-ci.yml configuration.

Here my situation:

  - stage1
  - stage2

  stage: stage1
  image: bash
    - ENV=$(some bash code to extract some info from Dockerfile)
    - echo $ENV ---> it works as aspected

  stage: stage2
  needs: [job1]
  image: $ENV

So i need to generate and environment on job1 and use it as image on job2. I see that “image” supports environments but i can’t find a way to use it from previous job. Any suggestion?

Gitlab Version: 15.0 (docker image)

Thanks for the help! :blush:

You can use a dynamic child pipeline to achieve this.

Here’s an MR that creates a dynamic pipeline to run container scanning jobs: ci: container scanning for controller and image dependencies (!1599) · Merge requests · / opstrace / opstrace · GitLab

The “magic” happens in:

      - artifact: .gitlab/ci/container_scanning.yml
        job: image scan config

The .gitlab/ci/container_scanning.yml artifact is generated in a previous job, and fed to the CI config via the job artifact type.

I try it but i receive this error

Found errors in your .gitlab-ci.yml:
jobs:python-build config contains unknown keys: trigger

It seems that doesn’t recognize “trigger” configuration

@fefo1993, that code snippet was only part of the relevant job:

image scan pipeline:
  stage: image_scanning
    - image scan config
      - artifact: .gitlab/ci/container_scanning.yml
        job: image scan config

Have a look at the link I shared in that comment as it contains the full MR diff.