Can a build task output variables for the next tasks (dynamic variables)?

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

Description of the problem

I would like to create a pipeline with dynamic variables. For instance, I want to create a build version using a custom logic and reuse this version in all tasks. The logic can be complex, so I prefer writing an executable. At the moment the problem is that the executable cannot set the environment variables of the parent process, so this doesn't work.

The pipeline will be something like:

build:
  script:
    - PrepareBuild.exe # This task would add a variable MyCustomVariable that the next task will be able to use as an environment variable
    - echo %MyCustomVariable%

Also, the variables won't flow through stages, but the workaround would be to use before_script.

Is is something possible with GitLab CI?

FYI, Azure Pipeline supports this scenario by reading custom log output (documentation)

echo ##vso[task.setvariable variable=myOutputVar;isOutput=true]this is the value
Edited by 🤖 GitLab Bot 🤖