1

当我通过我的 bitbucket 存储库推送到 master 时,我想将我的应用程序部署到 HEROKU。我的bitbucket-pipeline.yml文件设置似乎没有任何语法错误。

但是在阅读我的$HEROKU_API_KEY. 此密钥在我的.env文件中,并在我从文件中记录它时记录到控制台index.js

唯一可行的选择是将其复制api-key并粘贴到该行中。但我真的不想那样做。

我目前Ubuntu 18.04 LTSnode v10.16.3

我该如何解决这个难题?

这是yml文件

# This is a sample build configuration for JavaScript.
# Check our guides at https://confluence.atlassian.com/x/14UWN for more examples.
# Only use spaces to indent your .yml configuration.
# -----
# You can specify a custom docker image from Docker Hub as your build environment.
image: node:10.15.3

pipelines:
  default:
    - step:
        name: Defaults
        caches:
          - node
        script: # Modify the commands below to build your repository.
          - npm install
          - npm test
    - step:
        name: create artifact
        script:
          - mkdir artefacts
          - tar -czf artefacts/my-app-$BITBUCKET_BUILD_NUMBER.tar.gz --exclude=./artefacts .
          - cp artefacts/* .
        artifacts:
          - my-app-*.tar.gz
    - step:
        name: Deploy to production
        deployment: production
        script:
          - pipe: atlassian/heroku-deploy:1.0.1
            variables:
              HEROKU_API_KEY: $HEROKU_API_KEY
              HEROKU_APP_NAME: "my-app"
              ZIP_FILE: "my-app-$BITBUCKET_BUILD_NUMBER.tar.gz"
              WAIT: "true" # Optional.
              DEBUG: "false" # Optional


这是构建结果

位桶构建结果

4

2 回答 2

2

您应该使用存储库设置中的存储库变量来存储环境变量。我认为 Bitbucket Pipelines 不适用于 .env 文件。您可以在此处找到有关使用 Pipelines 环境变量的更多详细信息https://confluence.atlassian.com/bitbucket/variables-in-pipelines-794502608.html

于 2019-09-23T09:32:32.990 回答
0

我找到了解决方案。bitbucket 从在线存储库设置环境变量,它不使用本地存储库中的本地环境变量。

要访问它,您必须转到repository-> settings->deployment

Bitbucket 提供了 3 个默认的构建环境: - 测试 - 登台 - 生产

您可以为上述任何环境添加环境变量。

感谢 Alexander Zhukov 提供单挑。

于 2019-09-23T14:49:03.790 回答