6

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
  • Hi, how the things going? Does the Powershell on target machine task could help you achieve set variables in remote pipeline? Feel free to leave comment if you still has any puzzle or issue. Commented Oct 14, 2019 at 11:28

2 Answers 2

2

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.

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

2 Comments

The Powershell on Target Machine Task doesn't really fit my requirements. It requires a Username/ Password to connect. I'm connecting to a Ubuntu machine via a SSH Service Connection.
Also, it doesn't allow mapping secret Variables either - The secret gets blanked out ... So there's no way to access these on the remote secret.
0

It's an old one but it may help others searching for the answer how to get value of secret variable that was set in DevOps Pipelines Release. Adapt to your needs. Set a task

'SSH - run shell commands or a script on a remote machine using SSH'

Here is YAML view of task to save the secret variable value to a file on the remote machine:

steps:
- task: SSH@0
  displayName: 'Run shell inline on remote machine'
  inputs:
    sshEndpoint: '<your ssh connection name to remote machine>'
    runOptions: inline
    inline: |
     var1='$(NameOfYourSecretVariable)' bash -c 'echo $var1' > /<your custom path here>/tmp.log

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.