3

Let's considerate that I have a sonar.yml template with a parameter called build_tasks of type stepList as follows:

#sonar.yml

parameters:
  - name: build_tasks
    type: stepList
    default: []

steps:

- task: SonarQubePrepare@4
  displayName: 'Prepare Sonar analysis'
  inputs:
    SonarQube: 'SonarQube'
    scannerMode: 'MSBuild'
    projectKey: 'Bacon.Api'

- ${{ parameters.build_tasks }}

- task: SonarQubeAnalyze@4
  displayName: 'Run Sonar analysis'  
  
- task: SonarQubePublish@4
  displayName: 'Publish Sonar analysis'
  inputs:
    pollingTimeoutSec: '300'

And another template called build.yml:

#build.yml

steps:

- task: DotNetCoreCLI@2
  displayName: 'Restore'
  inputs:
    command: 'restore'
    projects: '**/*.sln'
    
- task: DotNetCoreCLI@2
  displayName: 'Build'
  inputs:
    command: 'build'
    arguments: '--no-restore'
    projects: '**/*.sln'

Would it be possible somehow to pass build.yml as the build_tasks parameter to sonar.yml?

Something along these lines:

#base.yml

jobs:

- job: sonar_analysis
  displayName: SonarQube
  pool:
    vmImage: 'ubuntu-latest'
  steps: 
    - template: sonar.yml
      parameters: 
        - build_tasks: build.yml
Rogerio Schmitt
  • 1,055
  • 1
  • 15
  • 35

1 Answers1

3

It turns out it is indeed possible.

I was just using the wrong syntax on my parameter, I've corrected it, and now everything is working as expected.

#base.yml

- job: sonar_analysis
  displayName: SonarQube
  pool:
    vmImage: 'ubuntu-latest'
  steps: 
    - template: sonar.yml
      parameters: 
        build_tasks: 
          - template: build.yml
Rogerio Schmitt
  • 1,055
  • 1
  • 15
  • 35