8

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.

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 [email protected] dev1/*: - step: name: Preparing pipeline script: - echo 'Preparing pipeline' - export BRANCH=$BITBUCKET_BRANCH - echo ${BRANCH} - curl -X POST "http://api.url.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 [email protected] 

Here is the response i get from pipeline

curl -X POST "http://api.url.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 % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed <!DOCTYPE html><!-- Illuminate\Database\QueryException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column &#039;branch&#039; cannot be null (SQL: insert into `branch` (`branch`, `repository_slug`, `updated_at`, `created_at`) values (, , 2019-04-02 08:38:02, 2019-04-02 08:38:02)) in file /home/api/vendor/laravel/framework/src/Illuminate/Database/Connection.php on line 664 Stack trace: 

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.

I need to send these variables in that curl command so I can save these variables into DB.

3
  • Posting the exact error you get from you pipeline could help Commented Apr 2, 2019 at 19:02
  • You are right :) I edited a question Commented Apr 3, 2019 at 6:00
  • Can you share a working curl request from your local machine? It would really help :) Commented Apr 4, 2019 at 0:32

1 Answer 1

11

Try to use

curl -d "{\"branch\":\"$BITBUCKET_BRANCH\",\"repository_slug\":\"$BITBUCKET_REPO_SLUG\"}" -H "Content-Type:application/json" -X POST http://api.url.com/api/savePipelineBranch 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.