Bitbucket Pipeline Yaml file

I’m new to SonarCloud and I just wanted to make sure this config is correct for the bitbucket-pipelines.yml file… The Repo houses Terraform, Python, and Go.

Thank you for the help in advanced.

image: atlassian/default-image:2  #quickest imag

clone:
  depth: full              # SonarCloud scanner needs the full history to assign issues properly

definitions:
  caches:
    sonar: ~/.sonar/cache  # Caching SonarCloud artifacts will speed up your build
  steps:
    - step: &sonar
        name: Sonar scan
        caches:
          - docker
          - sonar
        script:
          - pipe: sonarsource/sonarcloud-scan:1.2.0
            variables:
                EXTRA_ARGS: -Dsonar.organization=testorig -Dsonar.projectKey=testorig_devops -Dsonar.sources=. -Dsonar.host.url=https://sonarcloud.io
                SONAR_SCANNER_OPTS: -Xmx512m
                DEBUG: "true"
        services:
          - docker
pipelines:
  branches:
    '{master}':
      - step: *sonar
  pull-requests:
    "**":
      - step: *sonar

Hi @Devon_Ainsworth, welcome to the community forum!

Your pipeline seems a very good start! I only have a few suggestions to improve it.

First, a version 1.2.2 of the SonarCloud Scan pipeline has been released, I suggest to use it instead of the older 1.2.0.

I think the EXTRA_ARGS value should be enclosed in simple quotes, and the host URL is not required:

EXTRA_ARGS: '-Dsonar.organization=testorig -Dsonar.projectKey=testorig_devops -Dsonar.sources=.'

The DEBUG option makes the logs very verbose, I would advise to use it only for investigation, to analyze precisely the scanner behavior if it does not produce the expected results.

You can maybe take inspiration from this sample project. It’s for NodeJS (unfortunately we don’t have any sample for Go and Python yet), but removing the NodeJS specific stuff or changing it by your project build steps may help you.

Do you have some particular reason to use the syntax '{master}' in the branches definition? I would have used master or 'master', without brackets, as suggested in the Bitbucket pipeline branches configuration documentation.

HTH,
Claire

1 Like

Perfect!!! Thank you for the help.

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.