@1 tasks are deprecated and being dropped in the next release of SonarCloud. I'm trying to replace everything, but I keep getting:
##[error]ERROR: Project not found. Please check the 'sonar.projectKey' and 'sonar.organization' properties,
the 'SONAR_TOKEN' environment variable, or contact the project administrator to check the permissions of the user the token belongs to
Now, this is strange, as my @1 tasks work perfectly normal. This is what it looks like, for example:
- task: SonarSource.sonarcloud.14d9cde6-c1da-4d55-aa01-2965cd301255.SonarCloudPrepare@1
condition: succeeded()
displayName: "Prepare analysis on SonarCloud"
inputs:
SonarCloud: "SonarCloud - Analysis"
organization: "x-apps"
scannerMode: CLI
configMode: manual
cliProjectKey: "x"
cliProjectName: "x"
extraProperties: |
xxx
This works just fine, but when I try to replace the entire task name with: SonarCloudPrepare@2
, it tells me I'm missing all those values and credentials that are already in place, since @1 is working.
I do believe this is related to the huge name of the @1 task, but I can't figure out why is it like that, nor I can find an example of that online. Any help appreciated, thanks.
You can try to check with the following things:
On SonarCloud, open the project, and then navigate to "Administration" > "Analysis Method" > "Analyze a project with Azure DevOps Pipelines". Use the SonarCloud token displayed on step #2
(Add a new SonarCloud Service Endpoint
) to create a new SonarCloud service connection (or update the old service connection) in the project of Azure DevOps.
In the pipeline, configure the pipeline with SonarCloud v2 tasks like as below. Ensure the SonarCloud organization name, project key and name are consistent with the that displayed on the step #3
(Configure Azure Pipeline
) on the "Administration" > "Analysis Method" > "Analyze a project with Azure DevOps Pipelines" page of SonarCloud.
Below is one of my pipeline samples as reference. Here my project is .NET.
variables:
SonarCloudConnection: 'BriRanScOrg_MathCalc'
SonarCloudOrganization: 'briranscorg'
SonarCloudProjectKey: 'BriRanAdoOrg_MathCalc'
SonarCloudProjectName: 'MathCalc'
BuildConfiguration: 'Release'
steps:
- checkout: self
fetchDepth: 0
- task: SonarCloudPrepare@2
displayName: 'Prepare analysis on SonarCloud'
inputs:
SonarCloud: '$(SonarCloudConnection)'
organization: '$(SonarCloudOrganization)'
scannerMode: 'CLI'
configMode: 'manual'
cliProjectKey: '$(SonarCloudProjectKey)'
cliProjectName: '$(SonarCloudProjectName)'
cliSources: '.'
- task: DotNetCoreCLI@2
displayName: 'dotnet build'
inputs:
command: 'build'
projects: 'MathCalc.sln'
arguments: '-c $(BuildConfiguration)'
- task: SonarCloudAnalyze@2
displayName: 'Run Code Analysis'
- task: SonarCloudPublish@2
displayName: 'Publish Quality Gate Result'