4

In an Azure DevOps release pipeline, I have an Agent job. Within that Agent job, I have an Azure Powershell task. I do not see a way to specify environment variables for the Azure Powershell script that the Azure Powershell task runs.

You can do it in a build pipeline by simply specifying "env" for the Azure PowerShell task:

- task: AzurePowerShell@5
  inputs:
    azureSubscription: '...'
    ScriptType: 'FilePath'
    ScriptPath: '...'
    ScriptArguments: '...'
    FailOnStandardError: true
    azurePowerShellVersion: 'LatestVersion'
  env:
    USERNAME: $(username)
    PASSWORD: $(password)

But I don't see any way of specifying "env" in a release pipeline:

Screenshot showing no way to add environment variables

How can this be done?

2
  • Not get your response for several days, would you please share your latest information about this issue? If you have any concern, feel free to share it here. Commented Jul 15, 2020 at 7:45
  • @HughLin-MSFT Sorry for the delayed response. I just responded to your answer below. Commented Jul 28, 2020 at 16:25

2 Answers 2

1

When a pipeline executes, Azure will place all pipeline variables into environment variables, so any tools, scripts, tasks, or processes you run as part of the build can access parameters through the environment.

Defining variable in the DevOps pipeline GUI:

enter image description here

To get the secret variable in azure powershell task, just use the syntax of $(varibaleName) to work.

Sign up to request clarification or add additional context in comments.

6 Comments

This doesn't appear to be working for me. I have a secret pipeline variable named SERVERPASSWORD set to Release scope. I tried the following tests and each time SERVERPASSWORD was null: (1) Script file referencing $env:SERVERPASSWORD (2) Script file referencing $SERVERPASSWORD (3) Inline script referencing $env:SERVERPASSWORD (4) Inline script referencing $SERVERPASSWORD
I added a powershell task that runs "Get-ChildItem -Path Env:\" and I do not see my secret variables from the linked variable group or my pipeline variables. Non-secret variables do appear however.
I tested the syntax of $(varibaleName) , it works well .
@user1172282 It seems that this kind of issue has been solved, you could also consider to accept this answer. Have a nice day. :)
This question is related to this similar ticket.
|
-1

What I have done with variables in a powershell script in a release pipeline is use the variable Tab where you can either add the variable pair in the pipeline variables or create a variable group in the library section and then link it.

So if you create a variable pair for say compname computer1 then in the actual powershell script reference the variable as get-azvm -name $env:compname

This will then pull the variable you have added

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.