Bitbucket pipelines variables in curl

dominik_vavra April 2, 2019

Hi everyone,

I'm using bitbucket pipelines and in one step I want to call curl request to our API to save deployment data in DB.

But when I try to call curl with BITBUCKET_BRANCH and BITBUCKET_REPO_SLUG variables they are always empty or not filled at all.

This is my pipeline script:

image: php:7.1.1

pipelines:
branches:
master:
- step:
name: Preparing pipeline
script:
- echo 'Preparing pipeline'

- step:
name: Deploy to dev10
trigger: manual
deployment: staging
script:
- cat ./deploy.sh | ssh root@37.46.85.244
dev1/*:
- step:
name: Preparing pipeline
script:
- echo 'Preparing pipeline'
- export BRANCH=$BITBUCKET_BRANCH
- echo ${BRANCH}
- curl -X POST "http://api.creativehandles.com/api/savePipelineBranch" -H "Content-Type:application/x-www-form-urlencoded" -H "cache-control:no-cache" -H "content-type:multipart/form-data;" -F branch=${BRANCH} -F repository_slug=$BITBUCKET_REPO_SLUG

- step:
name: Deploy to dev1
trigger: manual
deployment: staging
script:
- cat ./deploy_dev1.sh | ssh root@37.46.85.244

You can see that for branches dev1/* I have the first step where I'm calling the curl with 2 variables. I tried two methods of using variables I found on the internet but none of them is working. I every time get the response from curl that variables are empty.

2 answers

0 votes
igoris.azanovas October 20, 2021

You need to escape from character sequence as you would do in terminal. You can find extensive answer on how to do this here: https://superuser.com/questions/835587/how-to-include-environment-variable-in-bash-line-curl 

0 votes
Ravi Jain August 8, 2019

hey, did you find any solution to this?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events