Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Is it possible to store the output of a pipe into a variable?

Rob Jahn Marketplace Partner Mar 09, 2020

This is a general question, but specifically I want to use this pipe atlassian/aws-eks-kubectl-run to run this command.....

kubectl get cm -n keptn keptn-domain -ojsonpath={.data.app_domain}

....and store that output into a variable for use in a another pipeline step.

Is this possible?  Can you show an example?

2 answers

1 accepted

0 votes
Answer accepted

Hi @Rob Jahn , I don't think this is possible with the current version of the pipe. We'll try to add such feature in the nearest future and let you know.

Rob Jahn Marketplace Partner Mar 10, 2020

I am also developing custom pipes.  Is it possible in general and if yes, is there an example you can point me to?

Yes, something similar is done in the aws-lambda-deploy pipe. It uses the artifacts feature to store the intermediate data between steps. You can see this guide as an example:

Rob Jahn Marketplace Partner Mar 11, 2020

Thanks Alex, but I am looking to see the the pipe itself can provide outputs. Use that lambda example, say the lambda returned a Json string. I would want to put that into a variable to then access and manipulate in a secondary pipeline step like a Unix command script step. 

Not sure if supported in general with pipes. For the kubectl pipe I would like to get output into string, for example from a kubectl get. And for my custom pipes, i want to expose outputs for consumption 

Rob Jahn Marketplace Partner Mar 16, 2020

@Alexander Zhukov - Hi Alex, just following up on my last post.

@Rob Jahn I don't think it's currently possible to store the output into a variable. The only way is to store the output of the pipe as an artifact and parse that artifact in the subsequent steps.

Rob Jahn Marketplace Partner Mar 17, 2020

Is there an example for this or just a code snippet example for what is needed in the pipe code for this that you can share or point me to? 

Rob Jahn Marketplace Partner Mar 17, 2020

I think I know what to do, but anything specific for the path of the file to write out? My custom pipe is Unix shell script.

Rob Jahn Marketplace Partner Mar 20, 2020

What I did was to create some file in the pipe and grab it use that file name as the artifact.  Then in a subsequent step, read in that artifact file.  I don't add in a folder path.  The file just lives in the root folder with the checked out code.

See the discussion on this thread, for it was a similar topic:

We had the same issue.

The general problem we had, when we are deploying to production we need to fetch the version from staging kubernetes and deploy the same version to production.

Sound easy oh?

The ideal solution will be

- pipe: atlassian/aws-eks-kubectl-run:1.2.3
KUBECTL_COMMAND: -n amplio-staging get pods --selector=app=amplio -o jsonpath='{.items[0].spec.containers[*].image}' > ./version.txt

However, it's not possible in bitbucket pipelines without dedicated support in the pipe.


We ended with

image: bitbucketpipelines/aws-eks-kubectl-run:1.2.3
- export CLUSTER_NAME="dev"
- export KUBECTL_COMMAND="get pods --selector=app=amplio -n amplio-staging -o jsonpath='{.items[0].spec.containers[*].image}'"
- python / > version.txt
- cat version.txt
- version.txt

Instead of using a pipe, we decide to take the docker itself and run the script by hand.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Bitbucket

⭐ Calling all Bitbucket and DevOps experts: Special showcase opportunity ⭐

Hi, Bitbucket community! Are you a DevOps practitioner (or know one in your network)? Do you have DevOps tips, tricks, or learnings you'd like to share with the community? If so, we'd love to hea...

1,487 views 4 8
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you