Reputation: 1943
I want to deploy my application to HEROKU when I push to master via my bitbucket repo. I have the bitbucket-pipeline.yml
file set-up which doesn't seem to have any syntax errors.
But the build fails while reading my $HEROKU_API_KEY
. This key is in my .env
file and logs to the console when I log it from the index.js
file.
The only feasible option is to copy the api-key
and paste it into that line. But I don't really don't wanna do that.
I am currently on Ubuntu 18.04 LTS
and node v10.16.3
How do I solve this puzzle?
# 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
Upvotes: 1
Views: 5092
Reputation: 1943
I found the solution. bitbucket sets environment variable from the online repository, it doesn't use the local environment variables in the local repo.
To access this, you have to go to the repository
-> settings
-> deployment
Bitbucket provides 3 default build environments: - testing - staging - production
You can add environment variables for any of the above environments.
Thanks to Alexander Zhukov for providing heads-up.
Upvotes: 0
Reputation: 4547
You should use the Repository Variables in the repository settings to store environment variables. I don't think Bitbucket Pipelines work with .env files. You can find more details about using Pipelines environment variables here https://confluence.atlassian.com/bitbucket/variables-in-pipelines-794502608.html.
Upvotes: 2