Astrophage
Astrophage

Reputation: 1429

Use Azure DevOps pipeline variable for resource repositories name in azure-pipelines.yml

I have a shared Azure pipeline yaml definition with the purpose to define one CodeAnalysis pipeline per repository.
How can I define the repository name dynamically?

I tried with name: '$(projectName)' which leads to the error:

The repository $(projectName) in project 8ab9d22b-6819-483b-829d-******* could not be retrieved. Verify the name and credentials being used.

azure-pipelines.yml

resources:
  repositories:
    - repository: codeAnalysisRepo
      type: git
      name: shared/codeanalysis
  
    - repository: SourceRepo
      type: git
      name: '$(projectName)'
  
jobs:
  - job: 'BackendCodeAnalysis'
    pool:
      name: '$(AgentPool)'

steps:
  - checkout: SourceRepo
    clean: true
        
  - template: sonarqube_msbuild_prepare.yml@codeAnalysisRepo
    parameters:
      projectKey: '$(project)'
      projectName: '$(project)'

  - task: DotNetCoreCLI@2
    displayName: "build DestRepo"
    inputs:
      command: 'build'
      projects: '$(Build.Repository.LocalPath)/**/*.csproj'
      configuration: Release

  - template: sonarqube_execute.yml@codeAnalysisRepo

It works when I hardcode the name

Upvotes: 1

Views: 3835

Answers (1)

Kim Xu-MSFT
Kim Xu-MSFT

Reputation: 2196

Currently, set parameter and variable is not supported in resources -> repositories.

A work around for this, you could set this at the checkout step. Here is s sample: Check out multiple repositories in your pipeline - Azure Pipelines | Microsoft Docs. Please note that, the repos should be in the same organization.

resources:
  repositories:
    - repository: Repo1
      type: git
      name: Artifacts/Repo1

  
jobs:
  - job: 'BackendCodeAnalysis'
    pool:
      vmimage: windows-latest

    steps:
      - checkout: git://$(projectName)
        clean: true

For your demand, you could create a suggestion ticket via: https://developercommunity.visualstudio.com/report?space=21&entry=problem.

Upvotes: 2

Related Questions