【问题标题】:Azure Build - How to get the user details who triggered the current build run and use that details for Git configAzure 构建 - 如何获取触发当前构建运行的用户详细信息并将该详细信息用于 Git 配置
【发布时间】:2021-08-12 06:49:57
【问题描述】:
【问题讨论】:
标签:
git
azure-devops
azure-pipelines
【解决方案1】:
Azure Devops Pipelines 中有几个不同的predefined system variables,它们拥有不同的身份。
Build.QueuedBy(和Build.QueuedById)
Build.RequestedFor(和Build.RequestedFor)
该值取决于导致构建的原因,下表可以在How are identitiy variables set下的文档中找到?
| If the build is triggered... |
Then the Build.QueuedBy and Build.QueuedById values are based on... |
Then the Build.RequestedFor and Build.RequestedForId values are based on... |
| In Git or TFVC by the Continuous integration (CI) triggers |
The system identity, for example: [DefaultCollection]\Project Collection Service Accounts |
The person who pushed or checked in the changes. |
| In Git or by a branch policy build. |
The system identity, for example: [DefaultCollection]\Project Collection Service Accounts |
The person who checked in the changes. |
| In TFVC by a gated check-in trigger |
The person who checked in the changes. |
The person who checked in the changes. |
| In Git or TFVC by the Scheduled triggers |
The system identity, for example: [DefaultCollection]\Project Collection Service Accounts |
The system identity, for example: [DefaultCollection]\Project Collection Service Accounts |
| Because you clicked the Queue build button |
You |
You |
根据您的问题,您正在寻找请求构建的用户(或生成将构建排队的操作,而不是进行实际排队的帐户(通常是服务帐户))。因此,您应该查看Build.RequestedFor 变量的用户名或Build.RequestedForId 的用户ID。
管道运行时的predefined system variables are injected as environment variables:
系统和用户定义的变量也作为环境注入
您的平台的变量。当变量变成
环境变量,变量名变成大写,句号
变成下划线。例如变量名 any.variable
变成变量名 $ANY_VARIABLE。