Share via

Azure DevOps Dynamic Repository CheckOUT!

Anonymous
2025-06-10T17:36:52.3+00:00

Trying to develop a multi-checkout tool in the pipeline that will enable to us to ghas scanning tool. Currently have a working pipeline for one repository at a time but would like to scale its capabilities. Looking for suggestions on what I can do to make this work efficiently?


# GHAS Security Scan for Databricks Notebook (.py) with Auto-Clean and Auto-Delete

trigger: none # Manual trigger to allow flexible input

parameters:
  
  - name: repository_name
    displayName: 'Repo to scan'
    type: string
    default: 'none'
    
  - name: branch_name
    displayName: 'Branch to scan'
    type: string
    default: 'none'

  - name: notebook_path
    displayName: 'Notebook Path (.py file)'
    type: string
    default: 'none'


variables:
  NOTEBOOK_PATH: ${{ parameters.notebook_path }}

pool:
  vmImage: 'ubuntu-latest'

steps:
  # 1. Checkout the code from the correct branch
  - checkout: self
    persistCredentials: true
    clean: true
    fetchDepth: 1

  # 2. Use Python 3
  - task: UsePythonVersion@0
    inputs:
      versionSpec: '3.x'
    displayName: 'Use Python 3'

 
  # 5. Initialize CodeQL scan
  - task: AdvancedSecurity-Codeql-Init@1
    inputs:
      languages: 'python'
      sourceRoot: '.'
    displayName: 'Initialize CodeQL'

  # 7. Run the CodeQL static analysis
  - task: AdvancedSecurity-Codeql-Analyze@1
    displayName: 'Run CodeQL Scan'

  # 8. Publish results to Security tab
  - task: AdvancedSecurity-Publish@1
    displayName: 'Publish CodeQL Results'

Azure DevOps
0 comments No comments

Answer accepted by question author

  1. Gaurav Kumar 790 Reputation points Moderator
    2025-06-11T05:00:09.0633333+00:00

    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 checkout with repository syntax:
    - 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.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.