user1632949
user1632949

Reputation: 635

How to deploy code from bit bucket to heroku?

while am doing auto deploying code from bit bucket to heroku, I got some configuration issue in bitbucket-pipelines.yml.

 HEROKU_API_KEY: 'XXXXXX'
 HEROKU_APP_NAME: 'XXXX'
 ZIP_FILE: 'your-app-sources.tar.gz'
 WAIT: 'true'

Above is the configuration for Heroku.

But while deploying it gives me an error near "ZIP_FILE":'..'

like that mentioned file/folder not found.

My question is which value i have to place for "ZIP_FILE":'XXXX'.

Please help me to go forward.

Note: am doing auto deployment from bitbucket to heroku for any push done on master branch. Thanks,SrinivasaRao.CH

Upvotes: 1

Views: 771

Answers (3)

Vasilis Zisis
Vasilis Zisis

Reputation: 33

You first need to create a step to build your code's image and generate that zip file there. Then create a step to deploy your code using the variables you are mentioning. So in your bitbucket-pipelines.yml file paste this:

image: node:10.15.0
    clone:
        depth: full
    
    pipelines:
        default:
        - step:
            name: Build
            caches:
                - node
            script:
                - npm install
                - git archive --format=tar.gz master -o your-app-sources.tar.gz
            artifacts: 
                - your-app-sources.tar.gz
        - step:
            name: Deploy
            deployment: production            
            script:
                - pipe: atlassian/heroku-deploy:1.2.1
            variables:
                HEROKU_API_KEY: $HEROKU_API_KEY
                HEROKU_APP_NAME: $HEROKU_APP_NAME
                ZIP_FILE: your-app-sources.tar.gz

Now every time you do a git push your code will auto-deploy on heroku. You do not need to use the WAIT part. Also 'your-app-sources' is a placeholder name. Just name it whatever you want.

Upvotes: 1

Elharony
Elharony

Reputation: 981

In your local project, generate a new tgz file of your project:

npm pack

Once done, copy the new .tgz generated name and paste it as the value of the "ZIP_FILE" attribute, and push it to your repo. This works for me!

Upvotes: 0

Israel Gboluwaga
Israel Gboluwaga

Reputation: 144

You can do this in a previous step in the deploy process.

- step:
   name: Create ZIP_FILE
   script:
     - tar czfv my_app.tgz /path/to/src
   artifacts:
     - my_app.tgz

Such that, you can access the tar.gz app in your next step (the one you have above).

Everything should look like this:

pipelines:
  default:
    - step:
        name: Create ZIP_FILE
        script:
          - tar czfv my_app.tgz /path/to/src
        artifacts:
          - my_app.tgz
    - step:
        name: Deploy to Heroku
        deployment: test   # set to test, staging or production
        script:
          - pipe: atlassian/heroku-deploy:1.1.1
            variables:
              HEROKU_API_KEY: $HEROKU_API_KEY
              HEROKU_APP_NAME: $HEROKU_APP_NAME
              ZIP_FILE: "my_app.tgz"

Upvotes: 0

Related Questions