在 Heroku 上推送到服务器时,Bitbucket 管道脚本没有更改文件

Bitbucket pipeline script didn't change the file when pushing to server on Heroku

我有这个管道配置文件bitbucket-pipelines.yml

# This script depends on two environment variables to be set in Bitbucket Pipelines
# 1. $HEROKU_API_KEY - Local environment var that contains your Heroku account's API key
# 2. $HEROKU_STAGING - Local environment var that contains your staging app name in Heroku
# 3. $HEROKU_PRODUCTION - Local environment var that contains your production app name in Heroku

 image: node:14

 # Doing a full clone to be able to push back to Heroku.
 clone:
   depth: full

 pipelines:
   branches:
     # When code is pushed to the staging branch it is deployed automatically to the staging environment.
     staging:
       - step:
           name: "Instalasi Server"
           caches:
            - node
           script:
            - npm install
            - chmod +x install.sh
            - ./install.sh
            - cat .env
            - git push -f https://heroku:$HEROKU_API_KEY@git.heroku.com/$HEROKU_STAGING.git staging:master

我试图将 .env.bitbucket 复制到 .env 个文件,包含在 install.sh.

install.sh

apt-get update && apt-get install nano
mv ./.env.bitbucket ./.env

结构文件夹

.env.bitbucket

PORT=3500
NODE_ENV=development
DEBUG=testrolling:*
DB_HOST=<host name>
DB_PORT=5432
DB_DATABASE=<database name>
DB_USERNAME=<database username>
DB_PASSWORD=<database password>
JWT_AUTH=<auth name>
JWT_EXPIRE=10m

.env

PORT=3500
NODE_ENV=development
DEBUG=testrolling:*
DB_HOST=localhost
DB_PORT=5432
DB_DATABASE=test_rolling
DB_USERNAME=postgres
DB_PASSWORD=
JWT_AUTH=test_rolling_glory
JWT_EXPIRE=10m

我尝试用 .env.bitbucket 替换 .env 文件,如下图所示,它工作正常。我尝试 运行 cat .env 并看到环境已经改变,就像 .env.bitbucket.

但是当我尝试 运行 在 heroku 上安装它时,.env 仍在使用旧的。如下图所示。

如何使用新的 .env 修复我通过 bitbucket 管道推送到 heroku 应用程序的 .env 文件?

https://www.zionandzion.com/setting-up-continuous-deployment-with-bitbucket-and-heroku/

于是终于得到了答案。 我只需要将 git commitgit add 添加到我的 bitbutcket 管道 yml 中即可使其正常工作。

之前:

# This script depends on two environment variables to be set in Bitbucket Pipelines
# 1. $HEROKU_API_KEY - Local environment var that contains your Heroku account's API key
# 2. $HEROKU_STAGING - Local environment var that contains your staging app name in Heroku
# 3. $HEROKU_PRODUCTION - Local environment var that contains your production app name in Heroku

 image: node:14

 # Doing a full clone to be able to push back to Heroku.
 clone:
   depth: full

 pipelines:
   branches:
     # When code is pushed to the staging branch it is deployed automatically to the staging environment.
     staging:
       - step:
           name: "Instalasi Server"
           caches:
            - node
           script:
            - npm install
            - chmod +x install.sh
            - ./install.sh
            - cat .env
            - git push -f https://heroku:$HEROKU_API_KEY@git.heroku.com/$HEROKU_STAGING.git staging:master

之后:

# This script depends on two environment variables to be set in Bitbucket Pipelines
# 1. $HEROKU_API_KEY - Local environment var that contains your Heroku account's API key
# 2. $HEROKU_STAGING - Local environment var that contains your staging app name in Heroku
# 3. $HEROKU_PRODUCTION - Local environment var that contains your production app name in Heroku

 image: node:14

 # Doing a full clone to be able to push back to Heroku.
 clone:
   depth: full

 pipelines:
   branches:
     # When code is pushed to the staging branch it is deployed automatically to the staging environment.
     staging:
       - step:
           name: "Instalasi Server"
           caches:
            - node
           script:
            - npm install
            - chmod +x install.sh
            - ./install.sh
            - cat .env
            - git status
            - git add . // add this
            - git commit -m 'change env' // add this
            - git push -f https://heroku:$HEROKU_API_KEY@git.heroku.com/$HEROKU_STAGING.git staging:master