I have a project I need to build in ADO that contains code in two different repos. Usually there is a matching release branch in both, but occasionally not. I would like to get the matching value and automatically fallback to main if there's no matching.

I was told instead to make the other repo a nuget package, or just compile to a dll, but those both seem like poor solutions when VS2022 now supports multi-repo solutions pretty cleanly.

1 Answer 1

- powershell: |
    $releaseBranch = "$(ReleaseBranchVariable)"  # Replace with the name of the release branch variable
    $mainBranch = "main"  # Specify the name of the main branch

    # Check if the release branch exists in the repository
    if (git branch --list --remote origin/$releaseBranch) {
        $branchToUse = $releaseBranch
    } else {
        Write-Host "Release branch not found, falling back to main branch."
        $branchToUse = $mainBranch

    Write-Host "Using branch: $branchToUse"

    # Check out the selected branch
    git checkout $branchToUse
  displayName: 'Select Branch'

This script checks if the release branch exists in the repository. If it does, it uses the release branch; otherwise, it falls back to the main branch.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.