❤️ ABS is one of the five Certified Kubernetes Service Providers in India ❤️

Setup Bitbucket Pipeline for simple NodeJS Application push it to the Docker with Timestamp

Configuring a Bitbucket Pipeline to build a simple Node.js application and push it to Docker Hub involves a series of steps. Here’s a step-by-step guide to configuring this pipeline:

  • A Bitbucket repository with your Node.js application’s source code
  • Docker installation
  • Docker Hub account
Step 1: Set up Your Node.js Application

Ensure that you have a Node.js application hosted in a Bitbucket repository. Your repository should contain a package.json file and any other necessary application files.

Step 2: Create a bitbucket-pipelines.yml File

In your Bitbucket repository, create a file named bitbucket-pipelines.yml. This file defines your CI/CD pipeline configuration.

Step 3: Configure the bitbucket-pipelines.yml File

Here’s an example bitbucket-pipelines.yml configuration to build a Node.js application, create a Docker image, and push it to Docker Hub:

					image: node:lts

 docker: true  # Enable Docker-in-Docker (DinD) support
   - step:
       name: Build and Push Docker Image backend1
       deployment: test
         - docker
         - node
         - docker
         - echo "$DOCKER_PASSWORD" | docker login --username "$DOCKER_USER" --password-stdin
         # Set the timezone to Indian UTC+5.30
         - export TZ=Asia/Kolkata

         # Generate a timestamp with the specified timezone
         - DOCKER_VERSION_TAG=$(date +"%Y%m%d%H%M%S")
         # Reset the timezone to UTC (optional)
         - export TZ=UTC

         - docker build -t username/imagename:$DOCKER_VERSION_TAG .
         - docker push username/imagename:$DOCKER_VERSION_TAG
  • Replace username and imagename with your Docker Hub username and the desired image name.
  • Make sure to set your Docker Hub credentials as environment variables in your Bitbucket repository settings. Go to “Settings” > “Repository settings” > “Pipeline” > “Environment variables” and add DOCKER_USER and DOCKER_PASSWORD.
Step 4: Commit and Push to Bitbucket

Commit the bitbucket-pipelines.yml file to your Bitbucket repository and push it. This will trigger the Bitbucket Pipeline to start building your Node.js application, creating a Docker image, and pushing it to Docker Hub.

Step 5: Monitor Your Pipeline

After pushing your changes, go to the “Pipelines” section in your Bitbucket repository. You can monitor the progress of your pipeline there. If everything is configured correctly, your Node.js application will be built, and the Docker image will be pushed to Docker Hub automatically.

Remember to adapt this configuration to your specific project requirements, including any additional build steps or Docker image tagging conventions you may use.