Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,455,656
Community Members
 
Community Events
175
Community Groups

Is there a way of sharing data between steps in bitbucket pipelines

I'm currently trying to use Bitbucket pipelines to deploy a docker container to Kubernetes. I've read the example that's already out there, but it doesn't completely fit our needs.

The step of building the container and putting it in it's registry works fine from the pipelines, as well is the deployment step that connects to Kubernetes to create a deployment, but not yet completely.

Because the build step knows the name of the container, which is constructed by Gradle, sharing this information to the deployment step would be convenient, so the kubectl commands can be executed using this information. Is there a way of sharing information between these steps?

2 answers

1 accepted

5 votes
Answer accepted
davina Atlassian Team Apr 19, 2018

Hi @Bram Wiekens

A way you can share data between steps is using artifacts which is configured in your bitbucket-pipelines.yml You could create a file that saves the data, and then pass it on. This is currently the only thing that is passed to and from steps that can be accessed.

Hope this helps!

Thank you @davina,that certainly helped give some direction for an alternative solution, which now works. I write a little file now during the build process and pass this file on as an artifact to the deployment step.

The only issue I had was to remember that the artifacts use relative paths to be shared so "/data/**" won't work while "data/**" will work. Other than that this is a working solution.

Deleted user Sep 01, 2018

Is there an example of how this works anywhere? How do you know the artifact's filename? Or path? Will it be automatically compressed? I don't see this documented anywhere.

Like Damien JARRY likes this

In your bitbucket-pipelines.yaml file, use something like this example:

pipelines:
  branches:
    master:
      - step:
        caches:
          - node
        script:
          - npm install
          - npm run fulltest
          - npm run get-version --silent > ./version.txt
        artifacts:
          - version.txt
      - step:
        script:
          - VERSION=$(cat ./version.txt)

 

The above configuration runs npm install, runs a full set of tests (custom npm task), and then uses get-version (a custom npm task to get the version of the package) and places the SemVer number into a file called version.txt.

This file is then stored as an artifact, which allows you to open it up in the next step (via cat, for example) and store it into a variable to be used further down in the step's script.

Like # people like this

Very good, thanks for this!

The problem with that solution is that artifacts get deleted after 2 Weeks. After that you cannot deploy anymore from that pipeline without starting a new build. In our case this would rollback the version in staging.

Hey, @davina  Imagine if I want to pass deployment variables from one step to another, I add them to a text/bash/env file and send it as an artifact. The important data can be leaked through the artifact. One solution is to encrypt in one step and decrypting in another.

if we ignore that, still, in the build log, bitbucket extracts and shows the contents of the variables.  I want to know is there a way to set variables received from the artifact to secured so bitbucket treats it as a secured variable and hides it in logs. Thanks. 

Like Attila Rakosi likes this

hi,
asking for help!

Im in a weird issue where I use artifacts to export 2 file (.txt and .tar) from the 1st step and I am not being able to get the .tar in the 2nd step. I can access the .txt file but not the .tar file. In both steps I use different docker images to process the data.


Is there anything to do with the docker image and artifacts exported in the 1st step? Asking this question because, if I use some different docker image in the 2nd step I can see the .tar file available.

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events