AzureDevOps YAML pipeline repository resource `ref` fallback

Viewed 1893

We are experimenting with AzureDevOps. We use git multirepo and, unfortunately, there are direct dependencies between different repos. With previous tool we used to match branches from different repositories by their name with a fallback to master - if branch XXX is not present on some repo than use master.

I'd like to achieve the same behavior with AzureDevOps YAML syntax. Here is my attempt.

resources:         
  repositories:
  - repository: repo      
    type: GitHub
    connection: myGitHubConnection
    source: primaryRepo
    ref: $(Build.SourceBranchName)
  - repository: repo      
    type: GitHub
    connection: myGitHubConnection
    source: secondaryRepo
    ref: $(Build.SourceBranchName)

It has one problem - if $(Build.SourceBranchName) is not present on secondaryRepo pipeline fails with message:

The pipeline is not valid. Could not get the latest source version for repository company/secondaryRepo hosted on GitHub using ref refs/heads/$(Build.SourceBranchName) ...

Where specific branch name is substituted (variable works).

Is there a way to specify fallback in case ref is invalid (branch does not exist)? I tried doing duplicate ref and using lists in YAML, but none succeeded.

1 Answers

Firstly, we haven't support using dynamic variables in ref. As of today, users must provide one fixed value here.

That's why you are receiving the message like using ref refs/heads/$(Build.SourceBranchName). You can directly see that the actual branch name does not been compiled successfully during the parse time.

Also, our system can only resolve the repositories once.

This means that once the system found one branch does not exist after the job parsed (normally, this job finished in initial step which finished before runtime), our system could not have a process to re-compiled it automatically, that is, fall back to the master branch.

enter image description here


We have take this suggestion into consideration, once it actual expanded, it may help achieve what you are looking for, because we can make expression condition and variables here. You can vote and comment it there, to raise its priority.

Is there a way to specify fallback in case ref is invalid (branch does not exist)?

The conditional expressions and variables does not allow to apply here, maybe they can be implemented in the form of APIs or scripts?

I'm afraid but must say, no, it is not possible to achieve until now.

As what you experienced, the whole pipeline will failed once our system found the branch does not exists there. If the pipeline is not running, the API/scripts cannot have any chance to perform operations(fall back).

Related