Pipeline change environment variable

Asked

Viewed 150 times

2

I have an environment variable of project level defined with the value X.

During the execution of the pipeline, given a certain condition, I need to change the value of this variable to Y.
The value needs to be persistent in the variable so that in the next execution the pipeline uses the value Y and not the X.

It is possible?
If yes, how?


Note: I will not post the code of my .gitlab-ci.yml because I could not evolve anything in relation to this subject, so I would not add in the question.

  • 1

    The way it was laid out here, I can’t think of any non-gambit method to do that. I didn’t study the Gitlab API in depth to suddenly make a CURL call and send a new value

  • Other alternatives I see are all involving external repositories, such as a cloud database or an application that receives the request. Not even caching will help you, because the gitlab cache is pretty chaotic

  • I don’t know if it was your idea, but your first comment got me thinking about consuming their REST API.. (Apparently you can do it) [https://docs.gitlab.com/ee/api/project_level_variables.html#update-variable], but it gets a little weird.. The pipeline is running in that environment, rather than making a export or something like I’ll need to make an HTTP request to do this job :P But... it seems to be the least solution strange @Jeffersonquesado

  • the export is not a good alternative, because in reality it only allows new child processes to see the environment variable. It does not affect ancestors, old children or "cousins" (as they are all children of PID 1, if it is neither descendant nor ancestor, then it is cousin). And the pipeline, in my opinion, does not run in the same environment, especially when Runner communicates with a Docker to upload the images. Then, each execution (each job distinct from each separate pipeline, even between two separate executions of the same job in the same pipeline) is done in a new amb

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.