SonarCLoud tasks worked for one pipeline and not for other pipeline

Same project and project name is ‘aus’ and has repo webstore-security.

with same configuration. SOnar cloud prepare , build and publish tasks successfully executed and reports got generated
and where as in another pipeline with in same repo and same project, and with same configuration it failed some error. Please suggest

Worked pipeline logs:

logs_1410.zip

Worked YAML file:

trigger:
  - none

pool:
  vmImage: ubuntu-latest

variables:
  buildConfiguration: 'Release'

stages:
- stage: 'BuildStage'
  displayName: 'Build Stage'
  jobs:
  - job: BuildAndPublish
    displayName: 'Build and Publish'
    steps:
    - checkout: self
      fetchDepth: 0
    - task: UseDotNet@2
      displayName: 'Use .NET 6'
      inputs:
        version: '6.x'
    - task: DotNetCoreCLI@2
      displayName: '.NET Restore'
      inputs:
        command: 'restore'
        projects: '**/*.csproj'
        feedsToUse: 'select'
    - task: SonarCloudPrepare@2
      inputs:
        SonarCloud: 'SonarCLoud'
        organization: 'nextops123'
        scannerMode: 'MSBuild'
        projectKey: 'nextops123_webstore-security'
        projectName: 'webstore-security'
    - task: DotNetCoreCLI@2
      displayName: '.NET Build'
      inputs:
        command: 'build'
        projects: '**/*.csproj'
        arguments: '--configuration $(buildConfiguration)'
    - task: DotNetCoreCLI@2
      displayName: '.NET Publish'
      inputs:
        command: 'publish'
        projects: '**/*.csproj'
        arguments: '--configuration $(buildConfiguration) --output $(Build.ArtifactStagingDirectory)'
    - task: SonarCloudAnalyze@2
      inputs:
        jdkversion: 'JAVA_HOME_17_X64'
    - task: SonarCloudPublish@2
      inputs:
        pollingTimeoutSec: '300'
    - task: PublishPipelineArtifact@1
      displayName: 'Publish Artifact'
      inputs:
        targetPath: '$(Build.ArtifactStagingDirectory)'
        artifact: 'ausemart-web'
        publishLocation: 'pipeline'

worked pipeline name: webstore-sec-sonar-ci

Failed pipeline logs:

logs_1409.zip

YAML file of failed pipeline:

trigger:

  • none

pool:
vmImage: ‘ubuntu-latest’

variables:
mend: true
parameters:

  • name: MendScan
    type: string
    default: false
    jobs:
  • job: BuildAndPublish
    displayName: ‘Build and Publish’
    steps:
    • checkout: self
      fetchDepth: 0
    • task: UseDotNet@2
      displayName: ‘Use .NET 6’
      inputs:
      version: ‘6.x’
    • task: DotNetCoreCLI@2
      displayName: ‘.NET Restore’
      inputs:
      command: ‘restore’
      projects: ‘**/*.csproj’
      feedsToUse: ‘select’
    • task: DotNetCoreCLI@2
      displayName: ‘.NET Build’
      inputs:
      command: ‘build’
      projects: ‘**/*.csproj’
      arguments: ‘–configuration Release’
    • template: templates/sonarcloudprepare.yaml
    • template: templates/sonarcloudbuildPublish.yaml
    • task: DotNetCoreCLI@2
      displayName: ‘.NET Publish’
      inputs:
      command: ‘publish’
      projects: ‘**/*.csproj’
      arguments: ‘–configuration Release --output $(Build.ArtifactStagingDirectory)’

- task: WhiteSource@21

inputs:

cwd: ‘$(System.DefaultWorkingDirectory)’

projectName: ‘webstore’

  • template: templates/mendbolt.yaml
  • task: PublishPipelineArtifact@1
    inputs:
    targetPath: ‘$(Build.ArtifactStagingDirectory)’
    artifact: ‘webstore’
    publishLocation: ‘pipeline’

faield pipeline name : Basic-Dotnet-Build

Please suggest. What Could be missing?

Hey there.

This link isn’t accessible.

@Colin PFA logs
Worked logs:

logs_1410.zip (192.2 KB)

Non worked logs:
logs_1409.zip (144.9 KB)

In the non-working pipeline, you don’t “sandwich” the build with the SonarCloud steps.

   - task: DotNetCoreCLI@2
      displayName: '.NET Build'
      inputs:
        command: 'build'
        projects: '**/*.csproj'
        arguments: '--configuration Release'
    - task: SonarCloudPrepare@2
      inputs:
        SonarCloud: 'SonarCLoud'
        organization: 'nextops123'
        scannerMode: 'MSBuild'
        projectKey: 'nextops123_webstore-security'
        projectName: 'webstore-security'
    - task: SonarCloudAnalyze@2
      inputs:
        jdkversion: 'JAVA_HOME_17_X64'
    - task: SonarCloudPublish@2

It should look more like this:

    - task: SonarCloudPrepare@2
      inputs:
        SonarCloud: 'SonarCLoud'
        organization: 'nextops123'
        scannerMode: 'MSBuild'
        projectKey: 'nextops123_webstore-security'
        projectName: 'webstore-security'
   - task: DotNetCoreCLI@2
      displayName: '.NET Build'
      inputs:
        command: 'build'
        projects: '**/*.csproj'
        arguments: '--configuration Release'
    - task: SonarCloudAnalyze@2
      inputs:
        jdkversion: 'JAVA_HOME_17_X64'
    - task: SonarCloudPublish@2
1 Like

@Colin You are right, I have moved the prepare analysis task after restore before build , I missed this step. Thank you for highlighting, it worked. you can close the case.