Details
-
Suggestion
-
Resolution: Duplicate
-
None
Description
Based on what I have read on the forum, each step of a Bitbucket Pipeline runs in a separate container. Also, there is currently no easy way to share environment variables between steps.
Here is an idea that would provide this without much work, assuming I'm not too wrong about how you implement pipelines: the basic idea is to automate the following approach that I currently use:
At the end of each step, I have some lines like this, that save variables into an artifact "shared_vars.sh", such that this artifact can be sourced in subsequent step:
# share variables with subsequent step(s): - echo export IMAGE_TAG=$IMAGE_TAG > shared_vars.sh - echo export IMAGE_NAME=$IMAGE_NAME >> shared_vars.sh
Then in subsequent steps I just need one line at the top of the script element, like this:
# get vars from previous step: - source shared_vars.sh
This seems very "automatable":
- have a section above pipelines where you can define variable names, eg
sharedVars: - IMAGE_TAG - IMAGE_NAME
- The bitbucket pipelines, when it creates the script from the list of lines under `script`, and copies it into the container (I'm guessing that's how it does it), it appends code to export the value of each var appearing in sharedVars, just like I did; the file would a temporary "hidden" artifact.
- Before each step, Pipelines inserts a line before the first line under script, to source that env-var-sharing artifact, and voila!
I'll see if I can submit a feature request for this.
Attachments
Issue Links
- is duplicated by
-
BCLOUD-20294 Propsal for sharing data between steps
- Gathering Interest