Sometimes there is a need for a Dev Ops to run the same activity for a bunch of repositories. You can always have a script to go through folders (repos) but checkout them manually is not a pleasant job. Moreover, it may need some tasks to be done with a pipeline plugin, but pipelines are usually for only 1 repo. Luckily, there is a way to run a pipeline for more that 1 repository and execute exactly the same tasks in parallel.
To do that, there is an interesting feature with Azure Dev Ops YAML pipelines strategy: matrix
. As documentation explaines, it generates copies of a job, each with different input. The only thing to worry about is to supply job details to the task. In my case it is a Sonarqube scan.
To deal with that, a special template
variable was added that refer to a yaml file that has a list of inputs.
The list example:
variables:
- name: reposToScan
value: >
{
repo1:
{
repoURL: "https://dev.azure.com/companyname/projectname/_git/repo1",
scanDirectory: "source"
},
repo2:
{
repoURL: "https://dev.azure.com/companyname/projectname/_git/repo2",
scanDirectory: "code"
}
}
The pipeline example:
trigger: none
variables:
- template: repositories_list.yaml
jobs:
- job: sonarqubeScan
strategy:
matrix: $[ variables.reposToScan ]
steps:
- checkout: self
clean: true
- task: SonarQubePrepare@5
inputs:
SonarQube: ${{ parameters.sonarqubeService }}
scannerMode: 'CLI'
configMode: 'file'
configFile: 'sonar.properties'
- task: SonarQubeAnalyze@5
- task: SonarQubePublish@5
Please take to account that it is just an example to illustrate how the strategy: matrix
feature can be used. I can’t guarantee that all the spaces are accurate here as editor is not that convinient as IDE.
The pipeline works well for me and I hope you can use it too where that suits.
There are more articles about Azure and PowerShell available.