Access pipeline variables via DevOps SSH task

Viewed 682

I have an SSH task in an Azure devops pipeline which connects to another target server to perform a deployment.

The target server does not have any of my pipeline's variables, nor do I have any means of passing them through the standard SSH Task. i.e., if I run pwd, none of my variables display.

Some of the variables are passwords.

What is the easiest way to pass these to my remote server?

1 Answers

Use PowerShell on Target Machine task with the PS script that set variable can help you to achieve this.

This task can help you connect the remote server then finish the powershell script.

For set variable script, you can check with this format Write-Verbose -verbose:

Param(
  [string]$psw
)
Write-Verbose "##vso[task.setvariable variable=NewPSWVariable]$psw" -verbose

enter image description here

I wrote the script in .ps1 file, then choose file path, call and pass the value to the parameter in PowerShell on Target Machine task.

What I used here is Write-Verbose. This can help to print out the variable into console which can help to debug the log.

Related