Use `needs` keyword in GitLab CI with variable stage name
13:18 08 Dec 2022

My pipeline has two different contexts, per se. If a developer is running on a branch other than main, a job called scan_sandbox is created on the pipeline of the merge request to scan the Dockerfile that the developer is working on currently.

When the branch is merged into main, a scan_production job is created, implying that the image is going to be pushed to the registry and later used in production environment.

My problem is to deal with this variable stage name, either scan_sandbox or scan_production with the needs statement, in order to fetch and publish the scan results. I've tried...

needs: ["scan_production", "scan_sandbox"]

But it returns an error, since both stages aren't going to be declared in different contexts. Also tried...

needs: ["container_scan"]

Which is the name of the stage where both scans will run, but GitLab CI also doesn't interpret it this way.

Anyone has any ideas?

Here is an image of the problem: Pipeline Flow

gitlab-ci