How to deploy an Angular/Nodejs app from bitbucket to heroku automatically

If its just a simple Angular static app and no Nodejs server, use this pipeline:



# 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: Build

            deployment: production

            caches:

              - node

            script:

              - npm install

              - npm install -g @angular/cli

              - npm run build

            artifacts:

              - dist/**

    - step:

            name: Create artifact

            script:

              - tar czfv application.tgz dist/

            artifacts:

              - application.tgz

    - step:

        caches:

          - node

        script: # Modify the commands below to build your repository.

          - pipe: atlassian/heroku-deploy:1.0.4

            variables:

              HEROKU_API_KEY: $HEROKU_API_KEY

              HEROKU_APP_NAME: $HEROKU_APP_NAME

              ZIP_FILE: "application.tgz"

         

         



If you have NodeJS, you have to let heroku see package.json, install dependencies, run postinstall code and see server.js (in root directory) by running this pipeline instead:


# 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:

  branches:

    master:

    - step:

        name: Push master to heroku

        deployment: production

        script:

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

         

         



These are variables you add in your bitbucket settings as either dependencies or environment variables
$HEROKU_API_KEY
$HEROKU_APP_NAME
Package.json:

"scripts": {
"ng": "ng",
"start": "node server.js",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"postinstall": "ng build --aot --prod"
},...
Add typescript, angular/cli and angular/compiler-cli to dependencies.


Comments