Search code examples
azureazure-devopsazure-pipelinesazure-pipelines-tasks

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


i have CI/CD environment in azure devops.i specially want to get the user name who pushed his code to trigger pipeline.i want to use this info as a variable inside the pipeline.do you guys know how can i do that ?


Solution

  • Actually we do have a predefined Build variable .

    We can directly use $(Build.RequestedFor) to get the the original user who kick off pipeline

    If you want to pass this variable to any other customized variable/parametes.

    You could use Logging Commands to set value during your build pipeline. ##vso[task.setvariable variable=testvar The first task can set a variable, and following tasks in the same phase are able to use the variable. The variable is exposed to the following tasks as an environment variable.

    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.

    More details please take a look at this tutorial 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