top of page
Get a Demo
Get a Free Quote

How to Deploy a React Application to Your Server Using Bitbucket Pipelines

Jul 29

3 min read

0

7

0

Using Bitbucket Pipelines to Deploy a React Application on Your Server


In today's fast-paced development environment, automating the deployment of your applications is crucial. Bitbucket Pipelines provides a powerful toolset to streamline the deployment process of a React application to your server. This guide will walk you through the steps, from setting up SSH keys to creating custom pipeline configurations, making the deployment process efficient and manageable.


Deploying a React application to your server from Bitbucket using pipelines is straightforward. Bitbucket offers a range of predefined configurations, such as deploying to AWS, which simplifies the setup process. For this guide, we will assume you have a Linux server and will deploy a React application from Bitbucket.



Connecting Servers Using SSH



Generate SSH Key Inside Bitbucket:

  1. Go to your repository settings.

  2. Navigate to 'Pipelines' and select 'SSH keys'.

  3. Choose 'Generate keys' to create public and private key pairs.


Adding Your Server to Known Hosts:

  • Add your server's host address.

  • Click on 'Fetch' to add your server to the known hosts.


Adding the Public Key to Your Server:

  1. Copy the public key from Bitbucket.

  2. SSH into your server.

  3. Find the file ~/.ssh/authorized_keys.

  4. Open the file and paste the copied public key.


Creating Custom Pipeline Configurations

Below is an example starter pipeline configuration. This configuration builds, tests, and deploys your React application using manual and parallel steps.

# Starter Pipeline Configuration
# Use this skeleton to build, test, and deploy using manual and parallel steps.

image: node:21.5.0

pipelines:
  default:
    - step:
        name: Build and test
        caches:
          - node
        script:
          - export NODE_OPTIONS="--max-old-space-size=8192"
          - npm install 
          - npm run build
        artifacts:
          - build/**
    - step:
        name: Deploy artifacts using SCP to PROD
        deployment: production
        size: 2x
        script:
          - pipe: atlassian/scp-deploy:0.3.3
            variables:
              USER: $USER
              SERVER: $SERVER
              REMOTE_PATH: 'path to server'
              LOCAL_PATH: 'build/*'

Setting Up Pipeline Variables

In the pipeline script, replace the placeholders with your actual values:

  • USER: The username for your server.

  • SERVER: Your server's address.

  • REMOTE_PATH: The destination path on your server where the build files will be deployed.

  • LOCAL_PATH: The path to your build directory, typically build/*.


Final Steps

Once configured, you can trigger this pipeline manually or set it to trigger automatically based on your Bitbucket repository settings. This automation ensures that your React application is always up-to-date on your server, enhancing deployment efficiency and reliability.



Conclusion

Deploying a React application from Bitbucket to your server using Pipelines is a robust and streamlined process. By leveraging SSH keys and custom pipeline configurations, you can automate the build, test, and deployment phases, ensuring smooth and consistent updates to your production environment. This guide serves as a comprehensive walkthrough for both beginners and seasoned developers, making deployment a breeze.

Feel free to share your experiences or ask questions in the comments below. Happy deploying!


FAQs

1. What is the advantage of using Bitbucket Pipelines for deployment?

Bitbucket Pipelines automates the build and deployment process, reducing manual errors and ensuring consistent application updates.

2. How secure is the deployment process using SSH keys?

SSH keys provide a secure method of authentication, ensuring that only authorized users can deploy to your server.

3. Can I use this pipeline configuration for other applications?

Yes, while this guide focuses on React applications, the principles and configurations can be adapted for other types of applications as well.


Engage With Us!

We'd love to hear your thoughts on deploying React applications using Bitbucket Pipelines. Share your experiences or questions in the comments below. Don't forget to share this article on social media to spread the knowledge!

Comments

Share Your ThoughtsBe the first to write a comment.
bottom of page