0
votes

I'm working with azure multistage pipelines, using deployment jobs with templates in a separate repo. I'm currently starting to use ARM templates in my deployment process and want to run ARM templates that are located in a different repository as well. This is where I get a little stuck, any help/advice appreciated.

To illustrate my setup:

  • Repo A -> Source code that has to be build and deployed to azure
  • Repo B -> Azure pipeline templates (only consists of yml files)
  • Repo C -> ARM templates

So what I want to accomplish: A uses B uses C.

REPO A: Documentation build and release yml

resources:
  repositories:
    - repository: templates
      type: git
      name: <ACCOUNT>/Azure.Pipelines.Templates
      ref: refs/tags/2.2.40

stages:
  - stage: Build
    jobs:
      - template: src/jobs/doc-build.yml@templates

  - stage: DEV
    jobs:
      - template: src/deployment-jobs/doc.yml@templates
    ....

REPO B: Documentation deployment

parameters:
  webAppName: ''
  connectedServiceName: 'DEV'

jobs:
  - deployment: doc_deploy
    pool:
      name: 'DOC'
    environment: 'doc'
    strategy:
      runOnce:
        deploy:
          steps:
            - template: ../deployment/arm-template.yml
              parameters:
                connectedServiceName: ${{ parameters.connectedServiceName }}
                resourceGroupName: 'documentation'
                templateFile: $(Build.SourcesDirectory)/Azure.ARM.Templates/src/web-app/documentation.jsonc
                paramFile: $(Build.SourcesDirectory)/Azure.ARM.Templates/src/web-app/documentation-params.json
                parameters: -name ${{ parameters.webAppName }}
            ...

REPO C: contains arm template + param file

The issue I'm facing is that I can't seem to be able to get to the files of repo c. I tried adding another repository entry on multiple levels but it does not seem to clone the dependent repo at all.

My current workaround/solution:

Use a powershell script to manually clone repo C and directly reference the file on disk.

Related github issue: https://github.com/microsoft/azure-pipelines-yaml/issues/103

1
i dont think you can make this work with multistage pipelines yet, but i would work with releases, you can specify a repo as an artifact and grab that artifact4c74356b41
@4c74356b41 I was afraid someone would say that. I had the same thought. I know it's possible using releases and since the yml templates setup is supported I was hoping to be able to do the same for the arm templates.Michael
I'm not 100% confident that's the way it is, but I'm fairly confident. you could work around with uploading templates to someplace and invoking them from url, or colocating them with templates code, for example4c74356b41
@4c74356b41 The ARM template documentation has examples for linked templates using blob storage. I've considered this setup but decided to manually script a git clone task to fetch the repo. I want to be able to stick to specific versions of my templates and figured a blob storage might be challenging to keep clean.Michael
i've been using build sha to store templates in the blob using sha as part of the path, that way I can always invoke the right version of the template from the blob storage and they dont collide4c74356b41

1 Answers

1
votes

I've also stumbled upon this issue, having to load arm templates from another repo into the current build. What I did was setting up a build on the arm-template-containing repo, producing a build artifact with following azure-pipelines.yml: (this would be your repo c)

trigger:
- master

steps:
- task: PublishBuildArtifacts@1
  inputs:
    PathtoPublish: '$(System.DefaultWorkingDirectory)/templates'
    ArtifactName: 'templates'
    publishLocation: 'Container'

Afterwards I could add following step into the actual pipeline:

- task: DownloadPipelineArtifact@2
            displayName: 'Get ARM Templates'
            inputs:
              buildType: 'specific'
              project: <YOUR-PROJECT-ID>'
              definition: '<ARM-BUILD-DEFINITION-ID>'
              buildVersionToDownload: 'latest'
              artifactName: 'scripts'
              targetPath: '$(Pipeline.Workspace)/templates'

and I was able to access the files as follows:

- task: AzureResourceGroupDeployment@2
            displayName: 'Create Queues $(ResourceGroup.Name) '
            inputs:
              azureSubscription: '<YOUR-SUBSCRIPTION>'
              resourceGroupName: '$(ResourceGroup.Name)'
              location: '$(ResourceGroup.Location)'
              csmFile: '$(Pipeline.Workspace)/templates/servicebus.json'

For more information about the Download Pipeline Artifact task check out following link: Download Pipeline Artifact task