]> source.dussan.org Git - sonarqube.git/commitdiff
[NO JIRA] Use YAML anchors to make Bitbucket Pipelines examples DRYer
authorWouter Admiraal <wouter.admiraal@sonarsource.com>
Wed, 5 Jan 2022 09:22:49 +0000 (10:22 +0100)
committersonartech <sonartech@sonarsource.com>
Thu, 6 Jan 2022 20:03:09 +0000 (20:03 +0000)
server/sonar-docs/src/pages/analysis/bitbucket-cloud-integration.md
server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/__tests__/__snapshots__/AnalysisCommand-test.tsx.snap
server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/commands/CFamily.ts
server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/commands/DotNet.ts
server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/commands/Gradle.ts
server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/commands/Maven.ts
server/sonar-web/src/main/js/components/tutorials/bitbucket-pipelines/commands/Others.ts

index e663286cb37053143d893044efb9a77c514c3660..272d5e0e106a5919f717272c795366ce2d9c2d59 100644 (file)
@@ -96,33 +96,29 @@ Click the scanner you're using below to expand the example configuration:
 | ```
 | 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]]
@@ -135,33 +131,29 @@ Click the scanner you're using below to expand the example configuration:
 | ```
 | 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]]
@@ -171,41 +163,36 @@ Click the scanner you're using below to expand the example configuration:
 | 
 | ```
 | 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
@@ -219,35 +206,33 @@ Click the scanner you're using below to expand the example configuration:
 |   [[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.
index 7384d2d1b4ece13b75aefd06e64c320d44792ffe..697363c2ecc66b86691d952f526855493513b75f 100644 (file)
@@ -31,28 +31,31 @@ exports[`should render correctly for cfamily 1`] = `
     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"
@@ -91,42 +94,34 @@ exports[`should render correctly for cfamily: with branch enabled 1`] = `
     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"
@@ -164,27 +159,30 @@ exports[`should render correctly for dotnet 1`] = `
   <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>
 `;
@@ -219,43 +217,33 @@ exports[`should render correctly for dotnet: with branch enabled 1`] = `
   <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>
 `;
@@ -291,23 +279,26 @@ exports[`should render correctly for gradle 1`] = `
     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>
 `;
@@ -343,33 +334,29 @@ exports[`should render correctly for gradle: with branch enabled 1`] = `
     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>
 `;
@@ -405,23 +392,26 @@ exports[`should render correctly for maven 1`] = `
     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>
 `;
@@ -457,33 +447,29 @@ exports[`should render correctly for maven: with branch enabled 1`] = `
     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>
 `;
@@ -519,23 +505,26 @@ exports[`should render correctly for other 1`] = `
     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>
 `;
@@ -571,33 +560,30 @@ exports[`should render correctly for other: with branch enabled 1`] = `
     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>
 `;
index bea52d0f86134136d87bfa94be4a6c73a52a97f8..3aa24a50cb3f4a5c2d71745d6363486be8cba2af 100644 (file)
 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`;
+}`;
 }
index 1cda1d0a7fd88bdbc1c2e0c09596b3b3f25eafb4..a2e7f9d5b9dc4610fab44dcc7a561b5a5bed2864 100644 (file)
 
 export default function dotNetExample(branchesEnabled: boolean, projectKey: string) {
   return `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:"${projectKey}" /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:"${projectKey}" /d:"sonar.login=\${SONAR_TOKEN}"  /d:"sonar.host.url=\${SONAR_HOST_URL}"
-            - dotnet build 
-            - dotnet sonarscanner end /d:"sonar.login=\${SONAR_TOKEN}"
-            ${
-              branchesEnabled
-                ? `
+      - step: *build-step
+${
+  branchesEnabled
+    ? `
   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:"${projectKey}" /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`
+    : ''
+}`;
 }
index 35afb573797d80ee1dfcfa92aa473f27da6460b1..8360c1d6c6f20ee460522e710842421ef910ffc6 100644 (file)
 export default function gradleExample(branchesEnabled: boolean) {
   return `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
 ${
   branchesEnabled
     ? `
   pull-requests:
     '**':
-      - step:
-          name: SonarQube analysis
-          caches:
-            - gradle
-            - sonar
-          script:
-            - bash ./gradlew sonarqube
-`
+      - step: *build-step`
     : ''
-}
-definitions:
-  caches:
-    sonar: ~/.sonar`;
+}`;
 }
index 9e63d9c4c62f78041c9db55cc4568feac9d11aaa..f45ad31efa7452509c2ac9544536c244a01867ed 100644 (file)
 export default function mavenExample(branchesEnabled: boolean, projectKey: string) {
   return `image: maven:3-openjdk-11
 
+definitions:
+  steps:
+    - step: &build-step
+        name: SonarQube analysis
+        caches:
+          - maven
+          - sonar
+        script:
+          - mvn verify sonar:sonar -Dsonar.projectKey=${projectKey}
+  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=${projectKey}
+      - step: *build-step
 ${
   branchesEnabled
     ? `
   pull-requests:
     '**':
-      - step:
-          name: SonarQube analysis
-          caches:
-            - maven
-            - sonar
-          script:
-            - mvn verify sonar:sonar -Dsonar.projectKey=${projectKey}
-`
+      - step: *build-step`
     : ''
-}  
-definitions:
-  caches:
-    sonar: ~/.sonar`;
+}`;
 }
index d06403f8b8c87bce14da5510435b6f5b44ac9167..3a918d36883a091ad29536a7e870f992495fd119 100644 (file)
 export default function othersExample(branchesEnabled: boolean) {
   return `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
 ${
   branchesEnabled
     ? `
   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.
+      - step: *build-step
 `
     : ''
-}  
-definitions:
-  caches:
-    sonar: ~/.sonar`;
+}`;
 }