Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Pipeline & Angular 6 CLI & Heroku 'ng build' not taking files

blubberbo June 3, 2018

Hi everyone,

I have been using a Pipeline to deploy my Angular (2+ with CLI) application to Heroku for some time and it has generally been working very. One of the things that is a little cumbersome, however, is that I have to run my 'npm run build' (which then runs the command: "ng build --prod --output-path=../dist/", check that in, merge it to my master branch and then have the pipeline run. Ideally, I could just use 'ng serve' in development, check in the changes, merge them to the master branch and have the Pipeline run the build command and then push the correct files.

I figured out how to have the pipeline run the build command, but then it does not push the proper files to Heroku, it pushes outdated files, not the ones it created. I am sure there is just something I fundamentally don't understand or missed. 

I just recently added the "cd ../" in my most recent attempt, but it didn't do anything. 

Do I have to do anything to pull the committed master branch but then the newly generated files, or to commit the newly generated files to the master branch?

All help is appreciated - below is my pipeline file:

image: node:8.9.4

clone:

depth: full

pipelines:

branches:

master:

- step:

script:

- npm install

- cd angular-src && npm install @angular-devkit/build-angular

- npm install @angular-devkit/build-optimizer

- npm install -g @angular/cli

- ng build --prod --output-path=../dist/

- cd ../

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

1 answer

0 votes
StannousBaratheon
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 23, 2018

Hi @blubberbo

If I understand your question correctly you are making changes to the checked out branch in your pipelines build and would like to deploy those changes to Heroku. This question specifically relates Heroku deployments so you might find related topics in their documentation and forums useful however let's see if we can help :)

To deploy your app to Heroku, you typically use the git push command to push the code from your local repository’s master branch to your heroku remote

https://devcenter.heroku.com/articles/git#deploying-code

Since Heroku deploys from your local branch, any changes you make must be committed to the local branch in order for them to be deployed. For example:

git add .
git commit
git push -f https://heroku:$HEROKU_API_KEY@git.heroku.com/$HEROKU_APP_NAME.git master

Be careful when doing this however as this will move the remote Heroku branch ahead of your repository branch so subsequent deploys could fail with the following error.

hint: Updates were rejected because the remote contains work that you do not have locally. This is usually caused by another repository pushing to the same ref. You may want to first integrate the remote changes (e.g., 'git pull ...') before pushing again.

To resolve this you can either:

  • force push to the heroku remote using `git push -f ...` (as shown in the above example)
  • push the local branch back to your repository before deploying to Heroku. When pushing changes back to your repository from within pipelines you should include "[skip ci]" in your commit message to prevent triggering another pipelines build.

I hope this helps.

Sam

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events