Dom*_*vra 4 git shell bitbucket bitbucket-pipelines
我正在使用 bitbucket 管道,并且在一个步骤中,我想向我们的 API 调用 curl 请求以将部署数据保存在数据库中。
但是当我尝试使用 BITBUCKET_BRANCH 和 BITBUCKET_REPO_SLUG 变量调用 curl 时,它们总是空的或根本没有填充。
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.42.83.244
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 root@37.41.82.255
Run Code Online (Sandbox Code Playgroud)
这是我从管道中得到的响应
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 'branch' 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:
Run Code Online (Sandbox Code Playgroud)
你可以看到,对于分支 dev1/* 我有第一步,我用 2 个变量调用 curl。我尝试了两种使用我在互联网上找到的变量的方法,但它们都不起作用。我每次都从 curl 得到变量为空的响应。
我需要在 curl 命令中发送这些变量,以便我可以将这些变量保存到数据库中。
小智 6
尝试使用
curl -d "{\"branch\":\"$BITBUCKET_BRANCH\",\"repository_slug\":\"$BITBUCKET_REPO_SLUG\"}" -H "Content-Type:application/json" -X POST http://api.url.com/api/savePipelineBranch
Run Code Online (Sandbox Code Playgroud)