admin管理员组文章数量:1400037
I have a problem with adding resources. Code is stored on BitBucket, authoritation through service connection.
resources:
repositories:
- repository: componentsPR
type: bitbucket
name: <my_project>
endpoint: '<my_connection>'
ref: ${{ variables['System.PullRequest.TargetBranch'] }}
- repository: components
type: bitbucket
name: <my_project>
endpoint: '<my_connection>'
ref: ${{ variables['Build.SourceBranch'] }}
The problem is - If it's PullRequest, then I don't have a ${{ variables['Build.SourceBranch'] }} branch in my project and pipeline fails.
In resources: repositories, I need to specify *
ref: ${{ variables['System.PullRequest.TargetBranch'] }}* - if Build.Reason is PullRequest,
or
ref: ${{ variables['Build.SourceBranch'] }} - in other cases.
Does someone know how to set if-else for this situation? I will appreciate any idea
I tried checkout, but endpoint was missed; tried $[eq(variables['Build.Reason'], 'PullRequest') ? variables['System.PullRequest.TargetBranch'] : variables['Build.SourceBranch']] - not working.
I have a problem with adding resources. Code is stored on BitBucket, authoritation through service connection.
resources:
repositories:
- repository: componentsPR
type: bitbucket
name: <my_project>
endpoint: '<my_connection>'
ref: ${{ variables['System.PullRequest.TargetBranch'] }}
- repository: components
type: bitbucket
name: <my_project>
endpoint: '<my_connection>'
ref: ${{ variables['Build.SourceBranch'] }}
The problem is - If it's PullRequest, then I don't have a ${{ variables['Build.SourceBranch'] }} branch in my project and pipeline fails.
In resources: repositories, I need to specify *
ref: ${{ variables['System.PullRequest.TargetBranch'] }}* - if Build.Reason is PullRequest,
or
ref: ${{ variables['Build.SourceBranch'] }} - in other cases.
Does someone know how to set if-else for this situation? I will appreciate any idea
I tried checkout, but endpoint was missed; tried $[eq(variables['Build.Reason'], 'PullRequest') ? variables['System.PullRequest.TargetBranch'] : variables['Build.SourceBranch']] - not working.
Share Improve this question asked Mar 24 at 20:35 AnnAnn 234 bronze badges 3 |1 Answer
Reset to default 1Expressions for ref
are supported, however if you were to write it like this:
resources:
repositories:
- repository: name
type: bitbucket
endpoint: <service-connection-name>
${{ if ne( variables['Build.BuildReason'], 'PullRequest') }}:
ref: ${{ variables['Build.SourceBranch'] }}
${{ else }}:
ref: ${{ variables['System.PullRequest.SourceBranch'] }}
...you'll get an error saying that template expressions aren't supported in this context.
Fortunately, sprint 248 introduced iif
which allows you to specify the if/else statement as a single expression.
resources:
repositories:
- repository: name
type: bitbucket
endpoint: <service-connection-name>
ref: ${{ iif( ne( variables['Build.BuildReason'], 'PullRequest'), variables['Build.SourceBranch'], variables['System.PullRequest.SourceBranch']) }}
本文标签:
版权声明:本文标题:continuous integration - How to choose ref branch conditionaly in resources block in Azure Pipelines? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744229443a2596256.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
componentsPR
andcomponents
are the same repo in bitbucket, you can useiif
expression as suggested by bryanbcook.ref: ${{ iif( eq( variables['Build.Reason'], 'PullRequest'), variables['System.PullRequest.TargetBranch'], variables['Build.SourceBranch']) }}
. If they are two different repos, please clarify if you want the pipeline to checkout repo "componentsPR" when triggered by a PR, and checkout repo "components" otherwise? – Ziyang Liu-MSFT Commented Mar 26 at 8:18