| ```
| image: openjdk:8
|
+| definitions:
+| steps:
+| - step: &build-step
+| name: SonarQube analysis
+| caches:
+| - gradle
+| - sonar
+| script:
+| - bash ./gradlew sonarqube
+| caches:
+| sonar: ~/.sonar
+|
| clone:
| depth: full
|
| pipelines:
| branches:
| '{master,main,develop}':
-| - step:
-| name: SonarQube analysis
-| caches:
-| - gradle
-| - sonar
-| script:
-| - bash ./gradlew sonarqube
+| - step: *build-step
|
| pull-requests:
| '**':
-| - step:
-| name: SonarQube analysis
-| caches:
-| - gradle
-| - sonar
-| script:
-| - bash ./gradlew sonarqube
-|
-| definitions:
-| caches:
-| sonar: ~/.sonar
+| - step: *build-step
| ```
[[collapse]]
| ```
| image: maven:3.3.9
|
+| definitions:
+| steps:
+| - step: &build-step
+| name: SonarQube analysis
+| caches:
+| - maven
+| - sonar
+| script:
+| - mvn verify sonar:sonar
+| caches:
+| sonar: ~/.sonar
+|
| clone:
| depth: full
|
| pipelines:
| branches:
| '{master,main,develop}':
-| - step:
-| name: SonarQube analysis
-| caches:
-| - maven
-| - sonar
-| script:
-| - mvn verify sonar:sonar
+| - step: *build-step
|
| pull-requests:
| '**':
-| - step:
-| name: SonarQube analysis
-| caches:
-| - maven
-| - sonar
-| script:
-| - mvn verify sonar:sonar
-|
-| definitions:
-| caches:
-| sonar: ~/.sonar
+| - step: *build-step
| ```
[[collapse]]
|
| ```
| image: mcr.microsoft.com/dotnet/core/sdk:latest
+|
+| definitions:
+| steps:
+| - step: &build-step
+| name: SonarQube analysis
+| caches:
+| - dotnetcore
+| - sonar
+| script:
+| - apt-get update
+| - apt-get install --yes openjdk-11-jre
+| - dotnet tool install --global dotnet-sonarscanner
+| - export PATH="$PATH:/root/.dotnet/tools"
+| - dotnet sonarscanner begin /k:"YOUR_PROJECT_KEY*" /d:"sonar.login=${SONAR_TOKEN}" /d:"sonar.host.url=${SONAR_HOST_URL}"
+| - dotnet build
+| - dotnet sonarscanner end /d:"sonar.login=${SONAR_TOKEN}"
+| caches:
+| sonar: ~/.sonar
+|
+| clone:
+| depth: full
+|
| pipelines:
| branches:
| '{master,main,develop}':
-| - step:
-| name: SonarQube analysis
-| caches:
-| - dotnetcore
-| - sonar
-| script:
-| - apt-get update
-| - apt-get install --yes openjdk-11-jre
-| - dotnet tool install --global dotnet-sonarscanner
-| - export PATH="$PATH:/root/.dotnet/tools"
-| - dotnet sonarscanner begin /k:"YOUR_PROJECT_KEY*" /d:"sonar.login=${SONAR_TOKEN}" /d:"sonar.host.url=${SONAR_HOST_URL}"
-| - dotnet build
-| - dotnet sonarscanner end /d:"sonar.login=${SONAR_TOKEN}"
+| - step: *build-step
| pull-requests:
| '**':
-| - step:
-| name: SonarQube analysis
-| caches:
-| - dotnetcore
-| - sonar
-| script:
-| - apt-get update
-| - apt-get install --yes openjdk-11-jre
-| - dotnet tool install --global dotnet-sonarscanner
-| - export PATH="$PATH:/root/.dotnet/tools"
-| - dotnet sonarscanner begin /k:"YOUR_PROJECT_KEY" /d:"sonar.login=${SONAR_TOKEN}" /d:"sonar.host.url=${SONAR_HOST_URL}"
-| - dotnet build
-| - dotnet sonarscanner end /d:"sonar.login=${SONAR_TOKEN}"
-| definitions:
-| caches:
-| sonar: ~/.sonar
-|```
+| - step: *build-step
+| ```
[[collapse]]
| ## SonarScanner CLI
| [[info]]
| | This configuration is an alternative to the SonarQube Scan Bitbucket Pipe. If you do not need a setup that allows for scanner caching, we recommend using the Bitbucket Pipe.
|
-| ```
-| clone:
-| depth: full
-|
-| pipelines:
-| branches:
-| '{master,main,develop}':
-| - step:
-| name: SonarQube analysis
-| image: sonarsource/sonar-scanner-cli:latest
-| caches:
-| - sonar
-| script:
-| - sonar-scanner
-|
-| pull-requests:
-| '**':
-| - step:
-| name: SonarQube analysis
-| image: sonarsource/sonar-scanner-cli:latest
-| caches:
-| - sonar
-| script:
-| - sonar-scanner
-|
-| definitions:
-| caches:
-| sonar: /opt/sonar-scanner/.sonar
-| ```
+| ```
+| image: maven:3.3.9
+|
+| definitions:
+| steps: &build-step
+| - step:
+| name: SonarQube analysis
+| image: sonarsource/sonar-scanner-cli:latest
+| caches:
+| - sonar
+| script:
+| - sonar-scanner
+| caches:
+| sonar: /opt/sonar-scanner/.sonar
+|
+| clone:
+| depth: full
+|
+| pipelines:
+| branches:
+| '{master,main,develop}':
+| - step: *build-step
+|
+| pull-requests:
+| '**':
+| - step: *build-step
+| ```
|
| [[info]]
| | A project key has to be provided through a `sonar-project.properties` file, or through the command line parameter. For more information, see the [SonarScanner](/analysis/scan/sonarscanner/) documentation.
yamlFileName="bitbucket-pipelines.yml"
yamlTemplate="image: <image ready for your build toolchain>
+definitions:
+ steps:
+ - step: &build-step
+ name: Download and install the build wrapper, build the project
+ script:
+ - mkdir $HOME/.sonar
+ - curl -sSLo $HOME/.sonar/build-wrapper-linux-x86.zip \${SONAR_HOST_URL}/static/cpp/build-wrapper-linux-x86.zip
+ - unzip -o $HOME/.sonar/build-wrapper-linux-x86.zip -d $HOME/.sonar/
+ - $HOME/.sonar/build-wrapper-linux-x86/build-wrapper-linux-x86-64 --out-dir bw-output <your clean build command>
+ - pipe: sonarsource/sonarqube-scan:1.0.0
+ variables:
+ EXTRA_ARGS: -Dsonar.cfamily.build-wrapper-output=bw-output
+ SONAR_HOST_URL: \${SONAR_HOST_URL}
+ SONAR_TOKEN: \${SONAR_TOKEN}
+ caches:
+ sonar: ~/.sonar
+
clone:
depth: full
pipelines:
branches:
'{master}': # or the name of your main branch
- - step:
- name: Download and install the build wrapper, build the project
- script:
- - mkdir $HOME/.sonar
- - curl -sSLo $HOME/.sonar/build-wrapper-linux-x86.zip \${SONAR_HOST_URL}/static/cpp/build-wrapper-linux-x86.zip
- - unzip -o $HOME/.sonar/build-wrapper-linux-x86.zip -d $HOME/.sonar/
- - $HOME/.sonar/build-wrapper-linux-x86/build-wrapper-linux-x86-64 --out-dir bw-output <your clean build command>
- - pipe: sonarsource/sonarqube-scan:1.0.0
- variables:
- EXTRA_ARGS: -Dsonar.cfamily.build-wrapper-output=bw-output
- SONAR_HOST_URL: \${SONAR_HOST_URL}
- SONAR_TOKEN: \${SONAR_TOKEN}
-
-definitions:
- caches:
- sonar: ~/.sonar"
+ - step: *build-step
+"
/>
<CompilationInfo
className="abs-width-800"
yamlFileName="bitbucket-pipelines.yml"
yamlTemplate="image: <image ready for your build toolchain>
+definitions:
+ steps:
+ - step: &build-step
+ name: Download and install the build wrapper, build the project
+ script:
+ - mkdir $HOME/.sonar
+ - curl -sSLo $HOME/.sonar/build-wrapper-linux-x86.zip \${SONAR_HOST_URL}/static/cpp/build-wrapper-linux-x86.zip
+ - unzip -o $HOME/.sonar/build-wrapper-linux-x86.zip -d $HOME/.sonar/
+ - $HOME/.sonar/build-wrapper-linux-x86/build-wrapper-linux-x86-64 --out-dir bw-output <your clean build command>
+ - pipe: sonarsource/sonarqube-scan:1.0.0
+ variables:
+ EXTRA_ARGS: -Dsonar.cfamily.build-wrapper-output=bw-output
+ SONAR_HOST_URL: \${SONAR_HOST_URL}
+ SONAR_TOKEN: \${SONAR_TOKEN}
+ caches:
+ sonar: ~/.sonar
+
clone:
depth: full
pipelines:
branches:
'{master}': # or the name of your main branch
- - step:
- name: Download and install the build wrapper, build the project
- script:
- - mkdir $HOME/.sonar
- - curl -sSLo $HOME/.sonar/build-wrapper-linux-x86.zip \${SONAR_HOST_URL}/static/cpp/build-wrapper-linux-x86.zip
- - unzip -o $HOME/.sonar/build-wrapper-linux-x86.zip -d $HOME/.sonar/
- - $HOME/.sonar/build-wrapper-linux-x86/build-wrapper-linux-x86-64 --out-dir bw-output <your clean build command>
- - pipe: sonarsource/sonarqube-scan:1.0.0
- variables:
- EXTRA_ARGS: -Dsonar.cfamily.build-wrapper-output=bw-output
- SONAR_HOST_URL: \${SONAR_HOST_URL}
- SONAR_TOKEN: \${SONAR_TOKEN}
+ - step: *build-step
pull-requests:
'**':
- - step:
- name: Download and install the build wrapper, build the project
- script:
- - mkdir $HOME/.sonar
- - curl -sSLo $HOME/.sonar/build-wrapper-linux-x86.zip \${SONAR_HOST_URL}/static/cpp/build-wrapper-linux-x86.zip
- - unzip -o $HOME/.sonar/build-wrapper-linux-x86.zip -d $HOME/.sonar/
- - $HOME/.sonar/build-wrapper-linux-x86/build-wrapper-linux-x86-64 --out-dir bw-output <your clean build command>
- - pipe: sonarsource/sonarqube-scan:1.0.0
- variables:
- EXTRA_ARGS: -Dsonar.cfamily.build-wrapper-output=bw-output
- SONAR_HOST_URL: \${SONAR_HOST_URL}
- SONAR_TOKEN: \${SONAR_TOKEN}
-definitions:
- caches:
- sonar: ~/.sonar"
+ - step: *build-step"
/>
<CompilationInfo
className="abs-width-800"
<CreateYmlFile
yamlFileName="bitbucket-pipelines.yml"
yamlTemplate="image: mcr.microsoft.com/dotnet/core/sdk:latest
-
+
+definitions:
+ steps:
+ - step: &build-step
+ name: SonarQube analysis
+ caches:
+ - dotnetcore
+ - sonar
+ script:
+ - apt-get update
+ - apt-get install --yes openjdk-11-jre
+ - dotnet tool install --global dotnet-sonarscanner
+ - export PATH=\\"$PATH:/root/.dotnet/tools\\"
+ - dotnet sonarscanner begin /k:\\"my-project\\" /d:\\"sonar.login=\${SONAR_TOKEN}\\" /d:\\"sonar.host.url=\${SONAR_HOST_URL}\\"
+ - dotnet build
+ - dotnet sonarscanner end /d:\\"sonar.login=\${SONAR_TOKEN}\\"
+ caches:
+ sonar: ~/.sonar
+
pipelines:
branches:
'{master}': # or the name of your main branch
- - step:
- name: SonarQube analysis
- caches:
- - dotnetcore
- - sonar
- script:
- - apt-get update
- - apt-get install --yes openjdk-11-jre
- - dotnet tool install --global dotnet-sonarscanner
- - export PATH=\\"$PATH:/root/.dotnet/tools\\"
- - dotnet sonarscanner begin /k:\\"my-project\\" /d:\\"sonar.login=\${SONAR_TOKEN}\\" /d:\\"sonar.host.url=\${SONAR_HOST_URL}\\"
- - dotnet build
- - dotnet sonarscanner end /d:\\"sonar.login=\${SONAR_TOKEN}\\"
-
-definitions:
- caches:
- sonar: ~/.sonar"
+ - step: *build-step
+"
/>
</Fragment>
`;
<CreateYmlFile
yamlFileName="bitbucket-pipelines.yml"
yamlTemplate="image: mcr.microsoft.com/dotnet/core/sdk:latest
-
+
+definitions:
+ steps:
+ - step: &build-step
+ name: SonarQube analysis
+ caches:
+ - dotnetcore
+ - sonar
+ script:
+ - apt-get update
+ - apt-get install --yes openjdk-11-jre
+ - dotnet tool install --global dotnet-sonarscanner
+ - export PATH=\\"$PATH:/root/.dotnet/tools\\"
+ - dotnet sonarscanner begin /k:\\"my-project\\" /d:\\"sonar.login=\${SONAR_TOKEN}\\" /d:\\"sonar.host.url=\${SONAR_HOST_URL}\\"
+ - dotnet build
+ - dotnet sonarscanner end /d:\\"sonar.login=\${SONAR_TOKEN}\\"
+ caches:
+ sonar: ~/.sonar
+
pipelines:
branches:
'{master}': # or the name of your main branch
- - step:
- name: SonarQube analysis
- caches:
- - dotnetcore
- - sonar
- script:
- - apt-get update
- - apt-get install --yes openjdk-11-jre
- - dotnet tool install --global dotnet-sonarscanner
- - export PATH=\\"$PATH:/root/.dotnet/tools\\"
- - dotnet sonarscanner begin /k:\\"my-project\\" /d:\\"sonar.login=\${SONAR_TOKEN}\\" /d:\\"sonar.host.url=\${SONAR_HOST_URL}\\"
- - dotnet build
- - dotnet sonarscanner end /d:\\"sonar.login=\${SONAR_TOKEN}\\"
-
+ - step: *build-step
+
pull-requests:
'**':
- - step:
- name: SonarQube analysis
- caches:
- - dotnetcore
- - sonar
- script:
- - apt-get update
- - apt-get install --yes openjdk-11-jre
- - dotnet tool install --global dotnet-sonarscanner
- - export PATH=\\"$PATH:/root/.dotnet/tools\\"
- - dotnet sonarscanner begin /k:\\"my-project\\" /d:\\"sonar.login=\${SONAR_TOKEN}\\" /d:\\"sonar.host.url=\${SONAR_HOST_URL}\\"
- - dotnet build
- - dotnet sonarscanner end /d:\\"sonar.login=\${SONAR_TOKEN}\\"
-
-definitions:
- caches:
- sonar: ~/.sonar"
+ - step: *build-step"
/>
</Fragment>
`;
yamlFileName="bitbucket-pipelines.yml"
yamlTemplate="image: openjdk:8
+definitions:
+ steps:
+ - step: &build-step
+ name: SonarQube analysis
+ caches:
+ - gradle
+ - sonar
+ script:
+ - bash ./gradlew sonarqube
+ caches:
+ sonar: ~/.sonar
+
clone:
depth: full
pipelines:
branches:
'{master}': # or the name of your main branch
- - step:
- name: SonarQube analysis
- caches:
- - gradle
- - sonar
- script:
- - bash ./gradlew sonarqube
-
-definitions:
- caches:
- sonar: ~/.sonar"
+ - step: *build-step
+"
/>
</Fragment>
`;
yamlFileName="bitbucket-pipelines.yml"
yamlTemplate="image: openjdk:8
+definitions:
+ steps:
+ - step: &build-step
+ name: SonarQube analysis
+ caches:
+ - gradle
+ - sonar
+ script:
+ - bash ./gradlew sonarqube
+ caches:
+ sonar: ~/.sonar
+
clone:
depth: full
pipelines:
branches:
'{master}': # or the name of your main branch
- - step:
- name: SonarQube analysis
- caches:
- - gradle
- - sonar
- script:
- - bash ./gradlew sonarqube
+ - step: *build-step
pull-requests:
'**':
- - step:
- name: SonarQube analysis
- caches:
- - gradle
- - sonar
- script:
- - bash ./gradlew sonarqube
-
-definitions:
- caches:
- sonar: ~/.sonar"
+ - step: *build-step"
/>
</Fragment>
`;
yamlFileName="bitbucket-pipelines.yml"
yamlTemplate="image: maven:3-openjdk-11
+definitions:
+ steps:
+ - step: &build-step
+ name: SonarQube analysis
+ caches:
+ - maven
+ - sonar
+ script:
+ - mvn verify sonar:sonar -Dsonar.projectKey=my-project
+ caches:
+ sonar: ~/.sonar
+
clone:
depth: full
pipelines:
branches:
'{master}': # or the name of your main branch
- - step:
- name: SonarQube analysis
- caches:
- - maven
- - sonar
- script:
- - mvn verify sonar:sonar -Dsonar.projectKey=my-project
-
-definitions:
- caches:
- sonar: ~/.sonar"
+ - step: *build-step
+"
/>
</Fragment>
`;
yamlFileName="bitbucket-pipelines.yml"
yamlTemplate="image: maven:3-openjdk-11
+definitions:
+ steps:
+ - step: &build-step
+ name: SonarQube analysis
+ caches:
+ - maven
+ - sonar
+ script:
+ - mvn verify sonar:sonar -Dsonar.projectKey=my-project
+ caches:
+ sonar: ~/.sonar
+
clone:
depth: full
pipelines:
branches:
'{master}': # or the name of your main branch
- - step:
- name: SonarQube analysis
- caches:
- - maven
- - sonar
- script:
- - mvn verify sonar:sonar -Dsonar.projectKey=my-project
+ - step: *build-step
pull-requests:
'**':
- - step:
- name: SonarQube analysis
- caches:
- - maven
- - sonar
- script:
- - mvn verify sonar:sonar -Dsonar.projectKey=my-project
-
-definitions:
- caches:
- sonar: ~/.sonar"
+ - step: *build-step"
/>
</Fragment>
`;
yamlFileName="bitbucket-pipelines.yml"
yamlTemplate="image: maven:3.3.9
+definitions:
+ steps:
+ - step: &build-step
+ name: SonarQube analysis
+ script:
+ - pipe: sonarsource/sonarqube-scan:1.0.0
+ variables:
+ SONAR_HOST_URL: \${SONAR_HOST_URL} # Get the value from the repository/workspace variable.
+ SONAR_TOKEN: \${SONAR_TOKEN} # Get the value from the repository/workspace variable. You shouldn't set secret in clear text here.
+ caches:
+ sonar: ~/.sonar
+
clone:
depth: full
pipelines:
branches:
'{master}': # or the name of your main branch
- - step:
- name: SonarQube analysis
- script:
- - pipe: sonarsource/sonarqube-scan:1.0.0
- variables:
- SONAR_HOST_URL: \${SONAR_HOST_URL} # Get the value from the repository/workspace variable.
- SONAR_TOKEN: \${SONAR_TOKEN} # Get the value from the repository/workspace variable. You shouldn't set secret in clear text here.
-
-definitions:
- caches:
- sonar: ~/.sonar"
+ - step: *build-step
+"
/>
</Fragment>
`;
yamlFileName="bitbucket-pipelines.yml"
yamlTemplate="image: maven:3.3.9
+definitions:
+ steps:
+ - step: &build-step
+ name: SonarQube analysis
+ script:
+ - pipe: sonarsource/sonarqube-scan:1.0.0
+ variables:
+ SONAR_HOST_URL: \${SONAR_HOST_URL} # Get the value from the repository/workspace variable.
+ SONAR_TOKEN: \${SONAR_TOKEN} # Get the value from the repository/workspace variable. You shouldn't set secret in clear text here.
+ caches:
+ sonar: ~/.sonar
+
clone:
depth: full
pipelines:
branches:
'{master}': # or the name of your main branch
- - step:
- name: SonarQube analysis
- script:
- - pipe: sonarsource/sonarqube-scan:1.0.0
- variables:
- SONAR_HOST_URL: \${SONAR_HOST_URL} # Get the value from the repository/workspace variable.
- SONAR_TOKEN: \${SONAR_TOKEN} # Get the value from the repository/workspace variable. You shouldn't set secret in clear text here.
+ - step: *build-step
pull-requests:
'**':
- - step:
- name: SonarQube analysis
- script:
- - pipe: sonarsource/sonarqube-scan:1.0.0
- variables:
- SONAR_HOST_URL: \${SONAR_HOST_URL} # Get the value from the repository/workspace variable.
- SONAR_TOKEN: \${SONAR_TOKEN} # Get the value from the repository/workspace variable. You shouldn't set secret in clear text here.
-
-definitions:
- caches:
- sonar: ~/.sonar"
+ - step: *build-step
+"
/>
</Fragment>
`;
export default function cFamilyExample(branchesEnabled: boolean) {
return `image: <image ready for your build toolchain>
+definitions:
+ steps:
+ - step: &build-step
+ name: Download and install the build wrapper, build the project
+ script:
+ - mkdir $HOME/.sonar
+ - curl -sSLo $HOME/.sonar/build-wrapper-linux-x86.zip \${SONAR_HOST_URL}/static/cpp/build-wrapper-linux-x86.zip
+ - unzip -o $HOME/.sonar/build-wrapper-linux-x86.zip -d $HOME/.sonar/
+ - $HOME/.sonar/build-wrapper-linux-x86/build-wrapper-linux-x86-64 --out-dir bw-output <your clean build command>
+ - pipe: sonarsource/sonarqube-scan:1.0.0
+ variables:
+ EXTRA_ARGS: -Dsonar.cfamily.build-wrapper-output=bw-output
+ SONAR_HOST_URL: \${SONAR_HOST_URL}
+ SONAR_TOKEN: \${SONAR_TOKEN}
+ caches:
+ sonar: ~/.sonar
+
clone:
depth: full
pipelines:
branches:
'{master}': # or the name of your main branch
- - step:
- name: Download and install the build wrapper, build the project
- script:
- - mkdir $HOME/.sonar
- - curl -sSLo $HOME/.sonar/build-wrapper-linux-x86.zip \${SONAR_HOST_URL}/static/cpp/build-wrapper-linux-x86.zip
- - unzip -o $HOME/.sonar/build-wrapper-linux-x86.zip -d $HOME/.sonar/
- - $HOME/.sonar/build-wrapper-linux-x86/build-wrapper-linux-x86-64 --out-dir bw-output <your clean build command>
- - pipe: sonarsource/sonarqube-scan:1.0.0
- variables:
- EXTRA_ARGS: -Dsonar.cfamily.build-wrapper-output=bw-output
- SONAR_HOST_URL: \${SONAR_HOST_URL}
- SONAR_TOKEN: \${SONAR_TOKEN}
+ - step: *build-step
${
branchesEnabled
? `
pull-requests:
'**':
- - step:
- name: Download and install the build wrapper, build the project
- script:
- - mkdir $HOME/.sonar
- - curl -sSLo $HOME/.sonar/build-wrapper-linux-x86.zip \${SONAR_HOST_URL}/static/cpp/build-wrapper-linux-x86.zip
- - unzip -o $HOME/.sonar/build-wrapper-linux-x86.zip -d $HOME/.sonar/
- - $HOME/.sonar/build-wrapper-linux-x86/build-wrapper-linux-x86-64 --out-dir bw-output <your clean build command>
- - pipe: sonarsource/sonarqube-scan:1.0.0
- variables:
- EXTRA_ARGS: -Dsonar.cfamily.build-wrapper-output=bw-output
- SONAR_HOST_URL: \${SONAR_HOST_URL}
- SONAR_TOKEN: \${SONAR_TOKEN}`
+ - step: *build-step`
: ''
-}
-definitions:
- caches:
- sonar: ~/.sonar`;
+}`;
}