Documentation

Looking for something in particular?

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. Inside these containers, you can run commands (similar to how you might work on a local machine) but with all the advantages of a new system configured for your needs. 

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

Configuring Your Provar Project


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

You also need to configure the Provar project and the other required files 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 licenses.

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.

Creating a Project in Bitbucket

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

Configure your Bitbucket Pipelines


Step 1: Go to Pipelines.

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

Image showing how to access Pipelines to start the configuration

Image showing how to change the template to configure the pipelines

Image showing the bitbucket-pipelines.yml file configuration script

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 must mention the base docker image – Provar supports Java version 8, and test case execution requires ANT. So, we have taken the official photo of atlassian/default-image:2. We can also use frekele/ant:1.10.3-jdk8 image, which already has Java 8 and ant.

PROVAR_HOME is the folder’s path containing the latest Provar ANT files. This is referenced in the build.xml provar.home property.

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 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, 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.

Image showing the bitbucket-pipelines.yml file created in the Bitbucket repository

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

Image showing the Bitbucket Pipelines running

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

Image showing the Artifacts Tab

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 secret password. Mark it as secure, 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.

Parameterization using Environment Variables

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

Image showing how to access the environment variables in the build.xml file

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 the 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 schedule (i.e., Hourly, Weekly, or Daily). This will schedule your run as per the configuration.

Image showing how to schedule jobs in Bitbucket Pipelines

Executing BitBucket Pipelines using a REST API


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


Feedback

Was this article helpful for you?
Documentation library

Trying to raise a case with our support team?

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.

Scroll to Top