Must-share information (formatted with Markdown):
- which versions are you using (SonarQube Server / Community Build, Scanner, Plugin, and any relevant extension) : 2025.1
- how is SonarQube deployed: zip, Docker, Helm:- Zip
- what are you trying to achieve: Set Sonar Qube Tag using Rest API
- what have you tried so far to achieve this
Do not share screenshots of logs – share the text itself (bonus points for being well-formatted)!
I am trying to use Sonar Qube API using a token created under my account. I am sonar Qube Admin and has all the rights . When I use my user name and password the script work fine but when I try to use the token created. Token created as “Global Analysis”, also tried user token as well bit giving same error due to privileges.
Here is the script works with my user name and password
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$user = Read-Host "Please Enter UserName "
$securedValue = Read-Host "Please Enter Password " -AsSecureString
$bstr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($securedValue)
$value = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($bstr)
$combocred = "$($user):$($value)"
$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($combocred))
$headers = @{"Authorization" = "Basic "+$encodedCreds}
$headers = @{
Authorization = "Basic "+$encodedCreds
}
$body = @{
project = $projectKey
tags = $tags
}
$sonarqubeUrl = $(OURSONARQUBEURL)
$apiUrl = "/api/project_tags/set"
$projectKey = $(OURPROJECTKEY)
$tags="devopsteam"
$uri = "$sonarqubeUrl/api/project_tags/set"
try
{
$webRequest = Invoke-RestMethod -Uri $uri -Headers $headers -Method Post -Body $body
}
catch
{
Write-Host $_.Exception.Response
Write-Host "##vso[task.complete result=SucceededWithIssues;]"
}
I am trying o set up Project Tags while running the build pipeline
Here is the script with the token
$myToken = $(my_token)
#$headers = @{"Authorization" = "Bearer "+$myToken}
$projectKey = "DevOpsAuditReport"
$tags="devopsteam1"
$headers = @{
"Authorization" = "Bearer "+$mytoken }
$body = @{
project = $projectKey
tags = $tags
}
$sonarqubeUrl = "https://sonarqube.bluebayinvest.com"
$uri = "$sonarqubeUrl/api/project_tags/set"
try
{
$webRequest = Invoke-RestMethod -Uri $uri -Headers $headers -Method Post -Body $body
}
catch
{
Write-Host $_.Exception.Response
Write-Host "##vso[task.complete result=SucceededWithIssues;]"
}