Bitbucket Pipelines

Bitbucket Pipelines is an integrated CI/CD service, built into Bitbucket. It allows you to automatically build, test and even deploy your code based on a configuration file in your repository. Essentially, containers are created in the cloud and inside these containers you can run commands (similar to how you might on a local machine) but with all of the advantages of a fresh system that is configured for your needs. 

The following includes information about using Provar and Bitbucket Pipelines together. 

Configuring your Provar project


To set up Bitbucket Pipelines, you need to first create and configure the bitbucket-pipelines.yml file in the root directory of your repository.

You also need to configure the Provar project along with the other required files in order to publish it on the Bitbucket repository.

  • ProvarProject: It contains the files built in Provar such as test cases, the src folder, build.xml files, etc.
  • Provar License: This includes the .license folder containing execution licences.

Build.xml configuration


Edit the below information in the build.xml file.

  • provar.home: This value is the path of the ProvarHome folder which contains the latest ANT libraries
  • testproject.home: This value is the Provar project root in your repository
  • testproject.results: The Provar results directory in your repository
  • license.path: This is the path where the .license folder is located
<project default="runtests">
    <property environment="env"/>
    <property name="provar.home" value="${env.PROVAR_HOME}"/>
    <property name="testproject.home" value=".."/>
    <property name="testproject.results" value="../ANT/Results"/>
    <property name="secrets.password" value="${env.PROVARSECRETSPASSWORD}"/>
    <property name="testenvironment.secretspassword" value="${env.ProvarSecretsPassword_EnvName}"/>
    <taskdef name="Provar-Compile" classname="com.provar.testrunner.ant.CompileTask" classpath="${provar.home}/ant/ant-provar.jar"/>
    <taskdef name="Run-Test-Case" classname="com.provar.testrunner.ant.RunnerTask" classpath="${provar.home}/ant/ant-provar.jar;${provar.home}/ant/ant-provar-bundled.jar;${provar.home}/ant/ant-provar-sf.jar"/>
    <taskdef name="Test-Cycle-Report" classname="com.provar.testrunner.ant.TestCycleReportTask" classpath="${provar.home}/ant/ant-provar.jar;${provar.home}/ant/ant-provar-bundled.jar;${provar.home}/ant/ant-provar-sf.jar"/>
    
    <target name="runtests">
    
        <Provar-Compile provarHome="${provar.home}" projectPath="${testproject.home}"/>
    
        <Run-Test-Case provarHome="${provar.home}"
                projectPath="${testproject.home}"
                resultsPath="${testproject.results}"
                resultsPathDisposition="Increment"
                testEnvironment=""
                webBrowser="Chrome_Headless"
                webBrowserConfiguration="Full Screen"
                webBrowserProviderName="Desktop"
                webBrowserDeviceName="Full Screen"
                excludeCallableTestCases="true"
                salesforceMetadataCache="Reuse"
                projectCachePath="../../.provarCaches"
                testOutputlevel="WARNING"
                pluginOutputlevel="WARNING"
                stopTestRunOnError="false"
                secretsPassword="${secrets.password}"
                  testEnvironmentSecretsPassword="${testenvironment.secretspassword}"
                invokeTestRunMonitor="true"
                >
        
            <fileset id="testcases" dir="../tests"></fileset>

        </Run-Test-Case>

    </target>
</project>

Creating a project in Bitbucket


Step 1: Log in to your Bitbucket account.

Step 2: Create a new repository and list the project name, repository name and visibility level.

Step 3: Push the project configured above to the repository.

Configure your pipelines


Step 1: Go to Pipelines.

Step 2: Change the template to Other. Now we need to configure the bitbucket-pipelines.yml file.

Here is an example:

image: atlassian/default-image:2
pipelines:
 default:
   - step:
       services:
         - docker
       script:
       - apt-get update && apt install wget unzip xvfb
       - wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
       - echo 'deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main' | tee /etc/apt/sources.list.d/google-chrome.list
       - apt-get update
       - apt-get install google-chrome-stable -y
       - export PROVAR_HOME="$BITBUCKET_CLONE_DIR/ProvarHome"
       - mkdir $BITBUCKET_CLONE_DIR/ProvarHome
       - curl -O https://download.provartesting.com/latest/Provar_ANT_latest.zip
       - unzip -o Provar_ANT_latest.zip -d ProvarHome
       - rm Provar_ANT_latest.zip
       - cd ${BITBUCKET_CLONE_DIR}/test/ANT
       - xvfb-run ant -f build.xml
       artifacts: # defining the artifacts to be passed to each future step.
       - test/ANT/Results/*

Explanation of the sample script above


First, we need to mention the base docker image – Provar supports Java version 8 and test case execution requires ANT. So, we have taken the official image of atlassian/default-image:2. We can also use frekele/ant:1.10.3-jdk8 image which already have Java 8 and ant

PROVAR_HOME is the path of the folder which contains the latest Provar ANT files. This is referenced in the build.xml provar.home property.

As we need to execute our UI test cases on a browser which is why the Chrome installation is included. To execute test cases in headless mode, we also need to install xvfb. Before executing the actual test script section, install xvfb and run the xvfb service. Execute your test cases using the xvfb-run ant -f build.xml command.

Reports and artifacts


Step 1: To get the reports folder as artifacts in Bitbucket Pipelines, just add the following in bitbucket-pipelines.yml.

artifacts: # defining the artifacts to be passed to each future step.
    - test/ANT/Results/*

Step 2: Now commit the file. This will create a file named bitbucket-pipelines.yml in your Bitbucket repository.

Step 3: Go to Pipelines. You can see your pipeline running.

Step 4: Click on the Artifacts Tabs. You can download the artifacts here.

Parameterization using environment variables


Parameterizations can be used to execute the following:

  • Using the secrets and environments password
  • Adding data to the build.xml file at run time

To add variables to the repository, follow the below steps:

Step 1: Click the Repository Settings.

Step 2: Add a variable for the secrets password. Mark it as secured which will mask the value.

Step 3: Add a variable for the browser as well. This will help you to define the browser where the execution will be performed.

You can access the variables using the ${env.VARIABLENAME} format in the build.xml file as shown in the screenshot below.

Parallel testing


You can achieve parallel testing by configuring parallel steps in Bitbucket Pipelines. Add a set of steps in your bitbucket-pipelines.yml file in parallel block. These steps will be initiated in parallel by Bitbucket Pipelines so they can run independently and complete faster.

Here is an example:

image: "frekele/ant:1.10.3-jdk8"
pipelines:
default:
    - step:
            name: No parallel tag
            services:
              - docker
            script:
              - echo "Without parallel Tag"
    - parallel:
            - step:
                name: Parallel 1
                services:
                  - docker
              
                script:
                  - apt-get update && apt install wget unzip xvfb
                  - wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
                  - echo 'deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main' | tee /etc/apt/sources.list.d/google-chrome.list
                  - apt-get update
                  - apt-get install google-chrome-stable -y
                  - cd test/ANT && xvfb-run ant -f build.xml
                artifacts: # defining the artifacts to be passed to each future step.
                          - test/ANT/Results/*

            - step:
                name: Parallel 2
                services:
                - docker
                script:
                - apt-get update && apt install wget unzip xvfb
                  - wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
                  - echo 'deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main' | tee /etc/apt/sources.list.d/google-chrome.list
                  - apt-get update
                  - apt-get install google-chrome-stable -y
                  - cd test/ANT && xvfb-run ant -f build.xml
                artifacts: # defining the artifacts to be passed to each future step.
                          - test/ANT/Results/*

Job scheduling


You can schedule your jobs in Bitbucket Pipelines

Step 1: Go to Pipelines.

Step 2: Click on Schedules.

Step 3: Select your branch, pipeline and the schedule (i.e., Hourly, Weekly or Daily). This will schedule your run as per the configuration.

Executing BitBucket Pipelines using a REST API


If you would like to execute the pipeline from any external application or release management tool like Copado, Flosum, etc., you can use webhooks. For more information about incoming webhook requests, please refer to the following:

Documentation library

Other available resources

Looking for something different?

We use cookies to better understand how our website is used so we can tailor content for you. For more information about the different cookies we use please take a look at our Privacy Policy.