Categories
Getting Started
Updates
Cloud Solutions
Cloud Integrations
SaaS Integrations
Proxy Configuration
Ticketing and Financial Systems Integrations
IaC Cost Tracker Guides
Bitbucket Integration
Overview
This guide provides step-by-step instructions for integrating the Binadox Structure-As-Code Analyzer with your Bitbucket repository. This integration enables automated code analysis within your Bitbucket pipelines, enhancing your development workflow and code quality.
Once integrated, pricing will be automatically calculated after each push to the repository and added as a comment to the commit. Ensure that your account has the necessary permissions to write comments. If permissions are not granted, comments will appear every 24 hours. While this step is optional, it’s highly recommended for immediate feedback.
Integration Steps
1. Create a Pipeline in Bitbucket
Log in to your Bitbucket account.
Navigate to your project’s root directory. Select Pipelines from the left sidebar. Click Create pipeline or Create your first pipeline.
Choose a template (the Recommended option is suitable for most cases).
Create a new file named bitbucket-pipelines.yml.
2. Add the Binadox Script to the Pipeline
Copy the following script into the bitbucket-pipelines.yml file.
commonStep: &codeAnalyzer
step:
name: Binadox Structure-As-Code Analyzer
fail-fast: false
script:
- echo "Sending Data to Binadox"
- if [[ -n $BITBUCKET_PR_ID ]]; then
export EVENT_NAME=pull_request;
else
export EVENT_NAME=push;
fi
- RESULT=$(curl -sw '%{http_code}' -X POST "$BINADOX_SERVER_URL"
-H 'Content-Type:application/json'
-H "Authorization:ApiToken "$BINADOX_SECRET_TOKEN""
-d "{
\"project\":\""$BINADOX_PROJECT_NAME"\",
\"bitbucket_data\":{
\"eventName\":\""$EVENT_NAME"\",
\"branch\":\""$BITBUCKET_BRANCH"\",
\"commit\":\""$BITBUCKET_COMMIT"\",
\"workspace\":\""$BITBUCKET_WORKSPACE"\",
\"repository\":\""$BITBUCKET_REPO_SLUG"\"
}
}")
- echo $RESULT
- if [[ $RESULT == 200 ]]; then
echo "Binadox Structure-As-Code Analyzer Request sent";
exit 0;
else
echo "Binadox Structure-As-Code Analyzer Request failed";
exit 1;
fi
pipelines:
pull-requests:
'**':
- step:
name: Build PR
script:
- echo "Done PR"
- parallel:
steps:
- <<: *codeAnalyzer
default:
- step:
name: Build
script:
- echo "Done"
- parallel:
steps:
- <<: *codeAnalyzer
This script sets up the pipeline for the Binadox Structure-As-Code Analyzer, triggering both pull requests and pushes to the default branch.
Click the Commit file button to save the changes.
3. Generate a Secret Token in Binadox
Log in to your Binadox account. Navigate to System Configuration. Select the API section. Click the Create API button.
Fill in the Name field with a descriptive name for your API token. Click the Save button.
After creating the API, you will receive a key. Save this key securely, as you’ll need it in the next step.
4. Set up Environment Variables in Bitbucket
In your Bitbucket repository, go to Repository settings > Pipelines > Repository variables.
Add the following variables.
BINADOX_SERVER_URL
- Value: https://prod.binadox.com/api/1/organizations/pricing/callback/analyze_iaac
- Keep this variable unsecured
BINADOX_PROJECT_NAME
- Value: Your Binadox project name
- Keep this variable unsecured
BINADOX_SECRET_TOKEN:
- Value: The API key generated in step 3
- Mark this variable as secured
Note:
Always keep your BINADOX_SECRET_TOKEN secure. Never expose it in your code or public repositories.
Support and Resources
- For further assistance, please contact Binadox support.
- Consult the Bitbucket Pipelines documentation for more information on pipeline configuration.
- Visit the Help Center for additional details on the Structure-As-Code Analyzer.
By following this guide, you’ve successfully integrated the Binadox Structure-As-Code Analyzer with your Bitbucket repository. This integration enables automated code analysis within your Bitbucket pipelines, enhancing your development workflow and code quality. For further assistance, please contact Binadox support or consult the Bitbucket Pipelines documentation.
Was this article helpful?
Thanks for the feedback!
Go Up