Passing variables to other steps

To this point, the only way I’ve been able to pass a variable (for example, a token) from one step to another is to write a file which contains that value.

This has been asked on here before, but I just want to check again and see if anything has changed and/or if others have come up with more elegant methods of doing this.

Thanks.

I’m considering giving this a try:

I assume you’ve tried it: can you set environment variables in one step and read them in another? I have the vague recollection I’ve done that with CircleCI, but I could be wrong.

No, if you set an environment variable in a step, it is local to that step. If I understand correctly, each step is run under its own bash command.

You can set environment variables per build, container, etc., and those are accessible throughout a job, but that’s not what I have in mind for this.

Thanks for the response.

Can you do export VAR=value in a step? I’ve not got an example to hand, but I wonder whether it would help.

That won’t work, each step is its own shell and the environment variables don’t carry over.

Gotcha. What’s your use case? Maybe you can just use a file in the tmp directory.

CircleCI just has terrible support for passing information from one step to another. Here’s the relevant documentation with their recommended workaround:

https://circleci.com/docs/2.0/env-vars/#using-bash_env-to-set-environment-variables

1 Like

The corner CircleCI has painted itself into, however, is that you can’t really use a BASH_ENV to pass a parameter to an orb or command. I’m not sure there’s actually any way to pass an interpolated value as a parameter to a command or an orb with the current set up.

My advice is that if you are this negative about any CI system, your CI project will fail - a positive mental attitude (and an inclination towards pragmatism) is essential to get it working and finished. If you want something that fits your use-case exactly, install Jenkins and maintain it yourself.

(I tend towards the view that hosted systems save time and frustration in the long run, even when taking work-arounds into account).

A positive attitude still won’t let you pass interpolated values to a command or orb, no matter how intensely positive it is.

15 Likes

Ha ha, true @apeschel :rofl:

However, it might help you find a workaround… :thinking:

I meant to follow up on this before, but apeschel actually posted the link to what I ended up doing anyway. It’s not elegant, but it works, at least for our use case.

I disagree about CircleCI having terrible support. They’ve always been very responsive for us whenever we submit a ticket or email a rep.

1 Like

I don’t think anyone is criticizing CircleCI support. The support quote was taken out of context. It was meant to point out specifically that the CircleCI platform has poor support for the specific feature of passing information between job steps.

2 Likes

I believe this feature request https://ideas.circleci.com/ideas/CCI-I-67 is what you are referring to.

To @dalefrancum-ncino I’m glad the workaround works for you.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.