如何将动态(用户信息)参数作为变量传递给 Azure 管道?

How to pass dynamic (user info) parameters as variable to azure pipelines?

我有 CI/CD 天蓝色的环境 devops.i 特别想获取推送他的代码触发的用户名 pipeline.i 想将此信息用作 pipeline.do 你们知道我该怎么做吗?

A​​zure Devops 将该信息传递给管道。检查 Build.RequestedFor 变量:Build variables (DevOps Services), How are the identity variables set?

In Git or TFVC by the Continuous integration (CI) triggers, the Build.RequestedFor and Build.RequestedForId values are based on the person who pushed or checked in the changes.

您可以在此处找到如何使用变量:Define variables

实际上我们有一个预定义的 Build variable .

我们可以直接使用$(Build.RequestedFor)获取原始开启流水线的用户

如果你想将此变量传递给任何其他自定义 variable/parametes。

您可以使用日志记录命令 在构建管道期间设置值。 ##vso[task.setvariable variable=testvar 第一个任务可以设置变量,同一阶段的后续任务可以使用该变量。该变量作为环境变量公开给以下任务。

Define and modify your variables in a script

To define or modify a variable from a script, use the task.setvariable logging command. Note that the updated variable value is scoped to the job being executed, and does not flow across jobs or stages. Variable names are transformed to uppercase, and the characters "." and " " are replaced by "_".

For example, Agent.WorkFolder becomes AGENT_WORKFOLDER. On Windows, you access this as %AGENT_WORKFOLDER% or $env:AGENT_WORKFOLDER. On Linux and macOS, you use $AGENT_WORKFOLDER.

更多详情请看这篇教程Define and modify your variables in a script You could also look at this blog: Use Azure DevOps Variables Inline powershell in build and release pipelines