Hi Ester, Sammy,
Azure DevOps Multi-Repo Checkout for GHAS Scanning using CodeQL
To dynamically scan multiple GitHub repository using Azure DevOps pipelines and GitHub Advanced Security (GHAS) with CodeQL, you can extend your pipeline to support multi-repo checkout, dynamic repo name/branch input, Reusable job templates for scalability and auto-cleanup post-analysis.
Follow the below workaround
Define Repository Parameters in Your Pipeline
parameters:
- name: repositories
type: object
default:
- name: 'repo1'
branch: 'main'
notebook_path: 'path/to/notebook1.py'
- name: 'repo2'
branch: 'dev'
notebook_path: 'notebooks/demo.py'
Loop Over Repositories with Matrix-Style Jobs
jobs:
- ${{ each repo in parameters.repositories }}:
- job: Scan_${{ repo.name }}
displayName: Scan ${{ repo.name }}
pool:
vmImage: 'ubuntu-latest'
steps:
- checkout: git://${{ repo.name }}
persistCredentials: true
clean: true
- task: UsePythonVersion@0
inputs:
versionSpec: '3.x'
- task: AdvancedSecurity-Codeql-Init@1
inputs:
languages: 'python'
sourceRoot: '.'
- task: AdvancedSecurity-Codeql-Analyze@1
- task: AdvancedSecurity-Publish@1
Please keep this in mind:
- The
git://syntax works for GitHub repositories if a service connection is configured. - For Azure Repos, you'll need to use the
checkoutwithrepositorysyntax:
- checkout: git://MyProject/RepoName@refs/heads/my-branch
Use a Reusable Template (Recommended)
Create a template file named ghas-template.yml:
parameters:
- name: repo_name
type: string
- name: branch_name
type: string
- name: notebook_path
type: string
jobs:
- job: Scan_${{ parameters.repo_name }}
displayName: Scan ${{ parameters.repo_name }}
pool:
vmImage: 'ubuntu-latest'
steps:
- checkout: git://${{ parameters.repo_name }}@${{ parameters.branch_name }}
persistCredentials: true
clean: true
- task: UsePythonVersion@0
inputs:
versionSpec: '3.x'
- task: AdvancedSecurity-Codeql-Init@1
inputs:
languages: 'python'
sourceRoot: '.'
- task: AdvancedSecurity-Codeql-Analyze@1
- task: AdvancedSecurity-Publish@1
Then, Reference the template from main pipeline:
jobs:
- ${{ each repo in parameters.repositories }}:
- template: ghas-template.yml
parameters:
repo_name: ${{ repo.name }}
branch_name: ${{ repo.branch }}
notebook_path: ${{ repo.notebook_path }}
For more details, please refer the following Microsoft documentation:
Multi-repo checkout in Azure Pipelines
Set up code scanning with GHAS
Reusable YAML templates in Azure Pipelines
I hope this information helps. Kindly consider upvoting the comment if the information provided is helpful. This can assist other community members in resolving similar issues.