Bitbucket with GCP
0 190
๐ Introduction to Bitbucket with GCP
Integrating Bitbucket with GCP (Google Cloud Platform) opens the door to powerful automation, efficient CI/CD pipelines, and seamless deployments. This blog post will guide you through setting up a practical workflow where Bitbucket repositories interact directly with GCP services like Cloud Run, App Engine, and Cloud Functions.
๐ง Why Integrate Bitbucket with GCP?
Using Bitbucket and GCP together helps developers automate testing, deployments, and rollbacks without relying on third-party CI/CD systems. Some key benefits include:
- End-to-end automation using Bitbucket Pipelines
- Direct deployment to GCP services
- Version-controlled infrastructure and source code
- Security via GCP IAM and service accounts
โ๏ธ Setting Up a Bitbucket Repository
To begin, create a Bitbucket repository for your project. You can do this through Bitbucket's UI or by pushing code from your local machine.
git init
git remote add origin https://bitbucket.org/your-username/your-repo.git
git add .
git commit -m "Initial commit"
git push -u origin master
๐ Creating a GCP Service Account
You need a service account to allow Bitbucket Pipelines to access GCP. Follow these steps:
- Go to IAM & Admin โ Service Accounts in GCP Console
- Create a new service account with necessary roles (e.g., Cloud Run Admin, Storage Admin)
- Generate and download a JSON key file
Now, store this JSON key securely in your Bitbucket repository as a secured environment variable.
๐ก Adding Environment Variables in Bitbucket
Go to your repository โ Settings โ Repository Variables and add:
- GCP_PROJECT โ your GCP project ID
- GCP_SA_KEY โ the entire content of your service account JSON (base64 encoded if needed)
๐ Sample Bitbucket Pipelines Configuration
Here's a basic bitbucket-pipelines.yml
that builds and deploys to Google Cloud Run:
image: google/cloud-sdk:slim
pipelines:
default:
- step:
name: Deploy to Cloud Run
script:
- echo $GCP_SA_KEY > gcp-key.json
- gcloud auth activate-service-account --key-file=gcp-key.json
- gcloud config set project $GCP_PROJECT
- gcloud builds submit --tag gcr.io/$GCP_PROJECT/my-app
- gcloud run deploy my-app \
--image gcr.io/$GCP_PROJECT/my-app \
--platform managed \
--region us-central1 \
--allow-unauthenticated
โ๏ธ Alternative Deployments with App Engine or Cloud Functions
You can also deploy to App Engine or Cloud Functions by tweaking your pipeline:
# For App Engine
- gcloud app deploy app.yaml
# For Cloud Functions
- gcloud functions deploy myFunction \
--runtime nodejs18 \
--trigger-http \
--allow-unauthenticated \
--entry-point=myFunction
๐งช Adding Tests to the Pipeline
Integrate automated tests to ensure your code is stable before deployment:
script:
- npm install
- npm run test
- if [ $? -eq 0 ]; then
echo "Tests passed. Proceeding to deployment.";
else
echo "Tests failed. Aborting."; exit 1;
fi
๐ Securing GCP Access
To prevent unauthorized access:
- Limit the service account permissions using the principle of least privilege
- Use short-lived authentication tokens when possible
- Encrypt secrets and avoid storing them in your codebase
๐ Monitoring Deployments
After deploying, monitor logs and app performance using GCP tools like Cloud Logging and Cloud Monitoring:
gcloud logging read "resource.type=cloud_run_revision" --limit 10
โ Final Thoughts
Setting up Bitbucket with GCP brings efficiency, control, and automation to your cloud deployment lifecycle. With secure authentication, Bitbucket Pipelines, and GCPโs powerful services, you can build, test, and deploy applications confidently and at scale.
If youโre passionate about building a successful blogging website, check out this helpful guide at Coding Tag โ How to Start a Successful Blog. It offers practical steps and expert tips to kickstart your blogging journey!
For dedicated UPSC exam preparation, we highly recommend visiting www.iasmania.com. It offers well-structured resources, current affairs, and subject-wise notes tailored specifically for aspirants. Start your journey today!

Share:
Comments
Waiting for your comments