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

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Forge app development. Part 3. Deployment

Edited

Bitbucket Pipelines

Ok, our app is fully functional (well, i've already mentioned some drawbacks, but hope you'll deal with it) and now we want to deploy it to our environments automatically. Atlassian gives us a great tool for this - Bitbucket Pipelines in Bitbucket Cloud. I choose Git as a de-facto standard. 

First of all we need to add additional dependency on order Bitbucket would be able to build our app. In your app folder run:

npm i @forge/cli@latest --save-dev

 Second -  we need to init repository in our app folder and then add/commit changes. Forge already provides .gitignore file. 

git init
git add .
git commit -m "Initial commit"

Then, go your Bitbucket Cloud (if you have no account yet - create it). Create new Git repository without README and .gitignore. Then we need to push our local project to cloud.

git remote add origin https://chemelson@bitbucket.org/chemelson/notes.git // change repo address to yours
git push -u origin --all 

All right! Next create file bitbucket-pipelines.yml in your app folder. This configuration file describe how our app will be deployed.

8.png

Then, create new branch from master - let's call it development. Don't forget to commit&push to cloud. 

Enable Pipelines in Repository Settings → Pipelines → Settings. 

In order to run forge CMD while building we need to add two environment variables. Go to Repository Settings → Pipelines → Repository Variables and create two secured vars - EMAIL (enter your email your use for Forge) and TOKEN (use token acquired in your account before). 

Wow, great work. Let' check. If you run tunnel, stop it. Check out development branch. Go to file NewNoteForm.js and insert such change:

// <ModalDialog header='New Note' onClose={() => show(false)}><ModalDialog header='Create Note' onClose={() => show(false)}>

 

Commit and push!

7.png

Modal window header changed. 

For now, on every commit to any branch except development BitBucket Pipelines will pick up changes and deploy tnem to Forge development environment. On commit to master branch it will auto deploy app to stage environment. In order to deploy to production we must trigger it manually in Pipelines interface. 

Conclusion

Forge is a great step toward increasing developer productivity. It is in Beta now, but it is under heavy development. Watch Forge change logs, build apps and be happy! 

All code from this tutorial can be found here

2 comments

Mohammed Amine Community Leader Mar 11, 2021

Excellent tuto @Anton Chemlev -_ Toolstrek _-

Hello,

Thanks for the tutorial.

When trying to use your code for bitbucket-pipeline.yml I get an access denied on forge login...
Even when I switch the variables for email, token for the real deal.

Locally I am able to login in "node_modules/.bin" using "forge login"

Any updates to forge that I need to consider since creation of the tutorial?

Thanks

I'm leaving this here in case someone has the same issue. This has taken way too much time to figure out.
I have changed the script of the relevant bitbucket-pipeline.yml to the
following:

script:
- npm install
- npm install @forge/cli@2.0.2 --omit optional
- npx forge settings set usage-analytics false
- npx forge login -u $EMAIL -t $TOKEN --non-interactive
- npx forge deploy -e development --non-interactive

PLEASE NOTE: This only works assuming you are not trying to deploy a custom-UI app. If the latter is the case (like in our scenario) we opted to also add the /build folder of our project to the git repo as installing those dependencies messed with the deployment even more.

massive Kudos to the people in this thread: https://community.developer.atlassian.com/t/how-to-use-forge-cli-in-a-ci-environment/46786

Like Wolfgang Landes likes this

Thanks a lot. Worked flawless!

Comment

Log in or Sign up to comment
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you