admin管理员组文章数量:1393850
I am working with Azure Pipelines. We are using a set of templates for different applications where each references a template. Part of the pipeline template includes updating updating work items with references. This works fine but when testing changes to the template files I have been unable to implement any kind of checks for whether the template used is from the main branch or not. Anybody know how to access the specific branch when it is set through resources in the devops UI?
All the obvious answers such as:
pwsh:
# Print information about the triggering source Write-Host "Triggering Repository: $env:BUILD_REPOSITORY_NAME" Write-Host "Triggering Branch: $env:BUILD_SOURCEBRANCH" Write-Host "Commit ID: $env:BUILD_SOURCEVERSION"
simply return info on the parent repository where the pipeline runs, I am interested in similar "commands"/approaches but for the template repository instead.
I am working with Azure Pipelines. We are using a set of templates for different applications where each references a template. Part of the pipeline template includes updating updating work items with references. This works fine but when testing changes to the template files I have been unable to implement any kind of checks for whether the template used is from the main branch or not. Anybody know how to access the specific branch when it is set through resources in the devops UI?
All the obvious answers such as:
pwsh:
# Print information about the triggering source Write-Host "Triggering Repository: $env:BUILD_REPOSITORY_NAME" Write-Host "Triggering Branch: $env:BUILD_SOURCEBRANCH" Write-Host "Commit ID: $env:BUILD_SOURCEVERSION"
simply return info on the parent repository where the pipeline runs, I am interested in similar "commands"/approaches but for the template repository instead.
Share Improve this question asked Mar 27 at 14:08 user30080501user30080501 1 2- Hi @user30080501, Welcome to SO. Have you got a chance to check the answer below and do the repo resource variables provide the values you intend to use? Thx for the update. – Alvin Zhao - MSFT Commented Mar 28 at 1:47
- Hi @user30080501, Good day to you. Can you please let us know if you have tried to use the variables in the answer below? If it resolves your query in this post, you may consider this, which may help others with similar concerns. Your sharing is much appreciated. – Aguy Commented Apr 1 at 2:03
1 Answer
Reset to default 1When you add a reference to a repository, there are a set of properties available on the resources object that you can use:
resources.repositories.<Alias>.name
resources.repositories.<Alias>.ref
resources.repositories.<Alias>.type
resources.repositories.<Alias>.id
resources.repositories.<Alias>.url
resources.repositories.<Alias>.version
You can access those properties using a runtime expression $[ <exp> ]
trigger: none
resources:
repositories:
- repository: templates # alias
type: git
name: Temp # projectName/repositoryName or just repositoryName
ref: main # optional
variables:
templateName: $[ resources.repositories.templates.name ]
templateRef: $[ resources.repositories.templates.ref ]
templateId: $[ resources.repositories.templates.id ]
templateVersion: $[ resources.repositories.templates.version ]
steps:
- pwsh: |
write-host "name: $(templateName)"
write-host "ref: $(templateRef)"
write-host "id: $(templateId)"
write-host "version: $(templateVersion)"
displayName: "show details about template repository"
Which produces the following output:
本文标签: Azure PipelinesReading Template Branch nameStack Overflow
版权声明:本文标题:Azure Pipelines - Reading Template Branch name - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744082576a2587920.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论