piecia
piecia

Reputation: 386

Azure devops pipeline - get branches from other repository

I have two repositories:

Default when I run a Azure pipeline I can choice between branch/tag of repository with pipeline definition. I would like to add a parameter with which I can select a branch from the source project.

Is this possible in a simple way in Azure? I don't want, I cannot keep definitions of pipelines in src_project.

In Jenkins, we used an additional method to fetch these branches, using the shared libraries plugin.

Upvotes: 2

Views: 1912

Answers (2)

piecia
piecia

Reputation: 386

@Shayki

Not exactly what I want. I use checkout step but with parameter:

- checkout: git://project/repo@{{parameters.BRANCH_NAME}}

Because of this, I cannot use the resources. And for parameters I have:

parameters:
  - name: BRANCH_NAME
    type: string
    default: develop

This is static method. I don't know how to dynamically fetch branches for a repository and pass them as values for the parameter.

Upvotes: 1

Shayki Abramczyk
Shayki Abramczyk

Reputation: 41565

You can do it with resources from type repositories:

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)
    trigger:  # CI trigger for this repository, no CI trigger if skipped (only works for Azure Repos)
      branches:
        include: [ string ] # branch names which will trigger a build
        exclude: [ string ] # branch names which will not
      tags:
        include: [ string ] # tag names which will trigger a build
        exclude: [ string ] # tag names which will not
      paths:
        include: [ string ] # file paths which must match to trigger a build
        exclude: [ string ] # file paths which will not trigger a build

And with checkout step, for example:

resources:
  repositories:
  - repository: MyAzureReposGitRepository # In a different organization
    endpoint: MyAzureReposGitServiceConnection
    type: git
    name: OtherProject/MyAzureReposGitRepo

trigger:
- main

pool:
  vmImage: 'ubuntu-latest'

steps:
- checkout: self
- checkout: MyAzureReposGitRepository

Upvotes: 2

Related Questions