【问题标题】: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
【问题描述】:

作为D365 - Azure Devops - Git Repo - How to check the history of a file which is stored in separate folders in the Main branch 建议的解决方案,我创建了一个主文件夹并将补丁文件手动复制到此备份存储库并在 ADO GIT 中提交以跟踪历史记录。

目前正在使用我的 PAT,每次签到都会显示我的用户 ID。

我想获取触发构建的用户详细信息,并使用他们的姓名、邮件 ID 和 PAT 并将它们用于 GIT 配置、提交和推送命令。

AZ Pipelines Build or Runs 命令行帮助已经完成的运行,我必须传递运行 ID。

az 管道运行显示 --id 13134 --org $orgname --project $projectname

我们是否可以选择获取当前运行的用户详细信息?

【问题讨论】:

    标签: 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。

    【讨论】:

      猜你喜欢
      • 2021-06-11
      • 1970-01-01
      • 2016-10-22
      • 2018-05-20
      • 2014-10-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-30
      相关资源
      最近更新 更多