Dominik Vávra
Dominik Vávra

Reputation: 108

Bitbucket pipelines variables in curl

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.

Upvotes: 8

Views: 9487

Answers (1)

msniezynski
msniezynski

Reputation: 161

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

Upvotes: 11

Related Questions