2

我正在尝试使用 bitbucket 管道为 heroku 中的两个应用程序部署应用程序从 git repo 接收到主分支,并且运行良好并且部署没有问题。

问题是当我尝试从名为“develop”的分支部署到 heroku 中的其他应用程序时,我在 bitbucket 的管道控制台上收到此错误错误

+ git push https://heroku:$HEROKU_API_KEY@git.heroku.com/$HEROKU_APP_NAME_DEV.git HEAD
remote: Pushed to non-master branch, skipping build.

这是我的 bitbucket-pipes.yml

  pipelines:
  default:
    - step:
        script: # Modify the commands below to build your repository.
          - npm install
          - git push https://heroku:$HEROKU_API_KEY@git.heroku.com/$HEROKU_APP_NAME.git HEAD
  branches:
    develop:
      - step:
          script:
            - npm install
            - git push https://heroku:$HEROKU_API_KEY@git.heroku.com/$HEROKU_APP_NAME_DEV.git HEAD
4

2 回答 2

1

我遵循了 Atlassian 的本教程:https ://confluence.atlassian.com/bitbucket/deploy-with-pull-requests-856832274.html ,您可以在此 repo 中找到解决方案:https ://bitbucket.org/rjst/ heroku-部署。这是您的 yaml 文件:

# This is a sample build configuration for Javascript.
# Only use spaces to indent your .yml configuration.
# -----
# You can specify a custom docker image from Docker Hub as your build environment.
image: node:4.6.0

pipelines:
  branches:
    master:
      - step:
          script:
            - npm install
            - export HEROKU_APP_NAME=$$HEROKU_APP_NAME
            - ./heroku_deploy.sh  
    develop:
      - step:
          script:
            - npm install
            - export HEROKU_APP_NAME=$HEROKU_APP_NAME_DEV
            - ./heroku_deploy.sh # Check https://bitbucket.org/rjst/heroku-deploy to understand how to deploy to Heroku

所以去那个仓库,在你的根目录中创建一个 bash 脚本的版本,在 yaml 旁边,并给它权限,即。chmod a+x heroku_deploy.sh然后设置你的环境变量。否则,这是脚本内容:

#!/bin/bash
# 
# Bash script to deploy to Heroku from Bitbucket Pipelines (or any other build system, with
# some simple modifications)
#
# This script depends on two environment variables to be set in Bitbucket Pipelines
# 1. $HEROKU_API_KEY - https://devcenter.heroku.com/articles/platform-api-quickstart
# 2. $HEROKU_APP_NAME - Your app name in Heroku
#

git archive --format=tar.gz -o deploy.tgz $BITBUCKET_COMMIT

HEROKU_VERSION=$BITBUCKET_COMMIT # BITBUCKET_COMMIT is populated automatically by Pipelines
APP_NAME=$HEROKU_APP_NAME

echo "Deploying Heroku Version $HEROKU_VERSION"

URL_BLOB=`curl -s -n -X POST https://api.heroku.com/apps/$APP_NAME/sources \
-H 'Accept: application/vnd.heroku+json; version=3' \
-H "Authorization: Bearer $HEROKU_API_KEY"`

PUT_URL=`echo $URL_BLOB | python -c 'import sys, json; print(json.load(sys.stdin)["source_blob"]["put_url"])'`
GET_URL=`echo $URL_BLOB | python -c 'import sys, json; print(json.load(sys.stdin)["source_blob"]["get_url"])'`

curl $PUT_URL  -X PUT -H 'Content-Type:' --data-binary @deploy.tgz

REQ_DATA="{\"source_blob\": {\"url\":\"$GET_URL\", \"version\": \"$HEROKU_VERSION\"}}"

BUILD_OUTPUT=`curl -s -n -X POST https://api.heroku.com/apps/$APP_NAME/builds \
-d "$REQ_DATA" \
-H 'Accept: application/vnd.heroku+json; version=3' \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $HEROKU_API_KEY"`

STREAM_URL=`echo $BUILD_OUTPUT | python -c 'import sys, json; print(json.load(sys.stdin)["output_stream_url"])'`

curl $STREAM_URL
于 2017-10-06T00:04:36.897 回答
1

这是因为 Heroku 想要从 master 分支构建,而您在 de pipeline.yml 中的推送命令不会推送到 master。

最简单和最简单的解决方案是更改 pipeline.yml 中的 push 命令,强制它推送到 heroku 的 master 分支。

将命令更改为:

- git push https://heroku:$HEROKU_API_KEY@git.heroku.com/$HEROKU_APP_NAME_DEV.git HEAD

至:

- git push https://heroku:$HEROKU_API_KEY@git.heroku.com/$HEROKU_APP_NAME_DEV.git HEAD:master
于 2018-04-07T10:18:42.703 回答