Jenkins + Bitbucket Repository

This example uses the following combinations of tools to achieve the integration:

  • SCM: Bitbucket Cloud

  • CI/CD: Jenkins

  • SAST Tool: Checkmarx One

Prerequisites

  1. Install Jenkins Plugin: Ensure the Bitbucket Branch Sourcearrow-up-right plugin is installed in Jenkins.

  2. Bitbucket API Token: Create a Bitbucket Tokenarrow-up-right. Specifically, this needs to be an API token with scopes. Under products, choose Bitbucket, and ensure the following permissions are granted:

    • read:project:bitbucket

    • write:repository:bitbucket

    • read:repository:bitbucket

    • read:pullrequest:bitbucket

    • write:pullrequest:bitbucket

  3. Add Bitbucket Token to Jenkins: Go to Jenkins -> Credentials -> Global -> Add Credentials.

    • Kind: Username with password

    • Username: Your Bitbucket account email

    • Password: The Bitbucket API token generated in step 2.

  4. Add Mobb API Token to Jenkins: Go back to Credentials, and add your Mobb API Token:

    • Kind: Secret text

    • Secret: Your Mobb API token. (Click here to learn how to create a Mobb API token)

    • ID: MOBB_API_TOKEN

  5. Add Checkmarx API Token to Jenkins: Go back to Credentials, and add your Checkmarx API Token:

    • Kind: Secret text

    • Secret: Your Checkmarx API token.

    • ID: CX_API_TOKEN

Step 1: Create a Jenkinsfile

Go to your Bitbucket repository and create a file named Jenkinsfile at the root of the project. Paste the following Groovy code into it:

Step 2: Configure Jenkins Multibranch Pipeline

  1. On the Jenkins homepage, click New Item.

  2. Enter an item name and select Multibranch Pipeline, then click OK.

  3. Under the Branch Sources section, click Add source and select Bitbucket.

  4. Configure the Bitbucket source:

    • Server: Bitbucket Cloud

    • Credentials: Select the Bitbucket API token credential you added earlier (Username with password).

    • Owner: Your Bitbucket organization name or workspace ID. (This should automatically populate the accessible repositories; select the correct repository).

  5. Under Build Configuration:

    • Mode: by Jenkinsfile

    • Script Path: Jenkinsfile

  6. Under Scan Multibranch Pipeline Triggers:

    • Check Periodically if not otherwise run.

    • Set the interval to 5 minutes (or down to your desired interval).

  7. Click Save.

This configuration will automatically trigger the Jenkins pipeline for any branches where the Jenkinsfile is located.

Expected Output

You can verify that Mobb ran successfully by checking the Build Console Output for your job. You should see an output similar to the following, which contains a link directing you to the Mobb fix report:

Last updated