How to use the Bitbucket Pipelines feature


Overview

Is your application code stored in a Bitbucket repository? Did you know that CAST Imaging on Cloud interfaces with Bitbucket Pipelinesexternal link so that you can run the entire code analysis workflow whenever you push or merge to your desired branch? This means that you can fully automate the analysis and generation of results in CAST Imaging on Cloud direct from your Bitbucket repository.

How does it work?

CAST Imaging on Cloud requires that your application source code is stored in a Bitbucket repository (public or private) and that you have access to Bitbucket Pipelinesexternal link in your Bitbucket account. Following that, a dedicated bitbucket-pipelines.yml file must be present at the root of your repository, containing instructions that will define when the Bitbucket Pipelines job is run, what it does and where the profiling and analysis results should be uploaded to.

Using the Bitbucket Pipelines feature effectively replaces the CAST Imaging Analyzer tool that you would normally download to your local machine to perform the required actions.

Prerequisites

  • A CAST Imaging on Cloud account
  • Source code stored in a Bitbucket repository (public or private)
  • Access to Bitbucket Pipelinesexternal link - all Bitbucket accounts (even those on the free tier) have access to Bitbucket Pipelines and include a certain number of “build” minutes, or you can use your own self-hosted “runner”
  • Ensure the Bitbucket Pipelines option is enabled in the repository via Repository settings > Pipelines > Settings:

How does Bitbucket charge for Bitbucket Pipelines?

All Bitbucket account tiers provide a number of “build” minutes per month (see Bitbucket pricingexternal link) to use Bitbucket’s own “runners”:

  • the CAST Imaging on Cloud workflows will fail when all bundled minutes are used up and you will not be able to launch any new jobs until the build minutes are reset, you subscribe to a paid tier, you purchase add-on build minutes or you use your own self-hosted “runners”.

It is not possible to predict how many “build” minutes your workflow for CAST Imaging on Cloud will use, but the larger the application, the longer it will take to complete. You should therefore ensure that you monitor your Bitbucket Pipelines usage.

How to onboard an application using Bitbucket Pipelines

Step 1 - Create the application in CAST Imaging on Cloud

In your CAST Imaging on Cloud account, click CI/CD Integration > Onboard application:

Name your application:

Then follow the instructions on screen:

Step 2 - Configure the Bitbucket Pipelines repository variable

In your Bitbucket account, navigate to the repository containing your application source code, then Repository settings > Pipelines > Repository variables > Add:

Create a new variable using the information provided to you in CAST Imaging on Cloud (this links your source code to the application in CAST Imaging on Cloud):

Field Value Notes
Name IMAGING_CLOUD_API_KEY Required
Value Provided by CAST Imaging on Cloud Unique per application
Secured ✅ Checked Recommended for sensitive data

Step 3 - Create a bitbucket-pipelines.yml file at the root of your repository

Create a bitbucket-pipelines.yml at the root of your repository in the “main” or “master” branch (i.e. the default). Paste in the code provided in CAST Imaging on Cloud and commit your changes:

Committing this file will automatically trigger a Bitbucket Pipelines build which you can see in Pipelines:

This workflow build will run the profiling and analysis steps and then upload the results into CAST Imaging on Cloud. When the workflow has completed, you can consult the results as normal in CAST Imaging on Cloud.

FAQ

How do I trigger a new Bitbucket Pipelines build?

The bitbucket-pipelines.yml file is configured to trigger a new build whenever you push/merge into the main or master branch, therefore generating new results in CAST Imaging on Cloud:

pipelines:
  branches:
    '{main,master,develop}':
      - step:
          name: Imaging Cloud Analyzer
          ...

You can change this behaviour if necessary by modifying the syntax as described in Pipelines YAML syntax referenceexternal link.

What if my Bitbucket Pipelines job exceeds the timeout?

By default all jobs have a 120 minute (2 hour) timeout - i.e. if the job exceeds this limit then it will be stopped by Bitbucket and will fail. This can occur when you are attempting to onboard a very large application with millions of lines of code. You can increase this timeout up to 12 hours, see Max-timeexternal link.

How do I redisplay the instructions in CAST Imaging on Cloud?

If you have navigated away from the instructions pop-up displayed in CAST Imaging on Cloud, you can redisplay using the Start analysis option: