Azure Devops Server 2022
SonarQube Community Edition Version 10.0
I have set up my Gradle task in pipeline as follows:
- task: Gradle@3
displayName: "gradlew build"
enabled: true
inputs:
gradleWrapperFile: 'pathgradlew.bat'
workingDirectory: 'hide'
options: '--stacktrace'
tasks: 'build'
publishJUnitResults: true
testResultsFiles: '***'
javaHomeOption: 'Path'
jdkDirectory: ''
sonarQubeRunAnalysis: true
sqGradlePluginVersionChoice: 'build'
spotBugsAnalysis: false
When I use sonarQubeRunAnalysis: true
it is working fine. But I do not want to Run analysis always. Thats why I declare a variable sqAnalyis, So I can control the Run Analysis in Sonarqube.
But When I am using the variable, the analysis is not working at all. I have tried as expression as well.
sonarQubeRunAnalysis: variables.sqAnalysis
or as expression
sonarQubeRunAnalysis: eq(variables.sqAnalysis, 'true')
I want to control Sonarqube analysis task for a pipeline using variable.
1
You should use $(var)
or ${{variables.sqAnalysis}}
for the variable value in the task:
sonarQubeRunAnalysis: '$(sqAnalysis)' #<---- marco syntax $(var)
or:
sonarQubeRunAnalysis: '${{variables.sqAnalysis}}' # <--- template expresson
Please refer to the doc What syntax should I use? for more details.
Or if you want to use the expression
, you need to put it in condition
, evaluate it to run the task when it’s true. If the value is false, it will skip the task.
- task: Gradle@3
condition: eq(variables.sqAnalysis, 'true')
...