nmca70
nmca70

Reputation: 313

Azure DevOps YAML Pipelines - can they pull a script from a repo?

In my graphical version of a release, I am connecting to an "Azure Repo" to pull in a script from it, not a BUILD artifact

Is this possible to do in YAML pipelines? So far it is very unclear, thanks in advance

The repo has a lot of scripts in it, so it doesn't need building or packaging up as a zip/drop package.

enter image description here

Upvotes: 1

Views: 3865

Answers (3)

Krzysztof Madej
Krzysztof Madej

Reputation: 40603

Yeah sorry,my bad. Yes it is possible. Following doc

If your pipeline has templates in another repository, or if you want to use multi-repo checkout with a repository that requires a service connection, you must let the system know about that repository. The repository keyword lets you specify an external repository.

resources:
  repositories:
  - repository: string  # identifier (A-Z, a-z, 0-9, and underscore)
    type: enum  # see the following "Type" topic
    name: string  # repository name (format depends on `type`)
    ref: string  # ref name to use; defaults to 'refs/heads/master'
    endpoint: string  # name of the service connection to use (for types that aren't Azure Repos)

Upvotes: 3

nmca70
nmca70

Reputation: 313

@Hugh Lin - MSFT @Krzysztof Madej

My Azure DevOps GIT repo called "AZDO_Scripts" (all part of the same project) and has a structure like this...

/Scripts/AzureCLI/ResourceGroup/Provision_ResourceGroup_withTags.ps1

My YAML is like this now...

name: $(date:yyyyMMdd)$(rev:.r)-$(SourceBranchName)

trigger:
- master

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

resources:
  repositories:
  - repository: commonscripts
    type: git
    name: AZDO_Scripts

stages:
- stage: Test
  variables:
    - name: resourcegroup
      value: 'rg-testthescript'
    - name: location
      value: 'WestEurope'
    - name: environmenttag
      value: 'Test'
  jobs:
    - job : TestJob
      pool:
        vmImage: 'windows-latest'
      steps:
      - task: AzureCLI@2
        inputs:
          azureSubscription: 'My-Azure-Sub-ServiceConnection'
          scriptType: 'ps'
          scriptLocation: 'scriptPath'
          scriptPath: 'Scripts/AzureCLI/ResourceGroup/Provision_ResourceGroup_withTags.ps1@commonscripts'
          arguments: '-resourcegroup $(resourcegroup) -location $(location) -environmenttag $(environmenttag)'

What do I need to do in the scriptPath: statement to reference that script? (2nd line from the bottom)

scriptPath: 'Scripts/AzureCLI/ResourceGroup/Provision_ResourceGroup_withTags.ps1@commonscripts'

Upvotes: 0

Hugh Lin
Hugh Lin

Reputation: 19391

A resource is any external service that is consumed as part of your pipeline. An example of a resource is another CI/CD pipeline that produces:

resources:
  pipelines: [ pipeline ]
  repositories: [ repository ]
  containers: [ container ]
  • Artifacts like Azure Pipelines or Jenkins.
  • Code repositories like GitHub, Azure Repos, or Git.
  • Container-image registries like Azure Container Registry or Docker hub.

Resources in YAML represent sources of pipelines, containers, repositories, and types. For more information on Resources, see here.

Upvotes: 2

Related Questions