0

I am trying to run a Powershell script on a remote machine via ssh. I have configured Azure release but I am getting a very strange error.

This is how my config file looks like

steps:
- task: SSH@0
  displayName: 'Run shell script on remote machine'
  inputs:
    sshEndpoint: 'Dev SSH service'
    failOnStdErr: false
    runOptions: script
    scriptPath: '$(Build.SourcesDirectory)/Pipelines/Scenarios/test.ps1'
    readyTimeout: '20000'

This is what my Powershell script looks like:

Write-Host "Hello, World!"

The remote computer is configured with ssh via PowerShell.

I am getting the error as shown in the picture

enter image description here

Transcription:

tr -d '\015' <./test.ps1> ./test.ps1._unix

##[error]At line:1 char:14

##[error]+ tr -d '\015' <./test.ps1> ./test.ps1._unix

##[error]The '<' operator is reserved for future use.

##[error]    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException

##[error]    + FullyQualifiedErrorId : RedirectionNotSupported

##[error]Error: Command tr -d '\015' <./test.ps1> ./test.ps1._unix exited with code 1.
6
  • 1
    It's looking like the remote host runs a Bash (or maybe sh) script which attempts to translate the line endings from Windows CRLF to Unix LF-only conventions. Only the admin of that system can really tell you what's going on, though perhaps this is something Microsoft does. (It would not be surprising, other than in that usually they would force you to use Windows when you don't want to, rather than the opposite.) Commented Jun 4, 2021 at 5:02
  • I am using windows server. Commented Jun 4, 2021 at 5:19
  • This is the scenario that works. - task: SSH@0 inputs: sshEndpoint: 'Dev SSH service' runOptions: 'commands' commands: 'Write-Host "Hello, World!" failOnStdErr: false readyTimeout: '20000' Commented Jun 4, 2021 at 5:20
  • I am vaguely guessing script means shell script and commands means Powershell, but I am only inferring from what you are reporting here; I have no familiarity with Azure. Commented Jun 4, 2021 at 5:23
  • @tripleee Is it possible to specify in yaml that I intend to use a ps script? Here is a link to the documentation link Commented Jun 4, 2021 at 5:24

2 Answers 2

1

I solved the problem. I have created a System.Debug variable. I saw how SSH0 works, in the end I just copy the script to the remote machine and execute it by setting Run = commands.

- task: CopyFilesOverSSH@0
  displayName: 'Copy scripts to on remote machine'
  inputs:
     sshEndpoint: 'Dev SSH service'
     sourceFolder: '$(Build.SourcesDirectory)\Pipelines\Scenarios'
     contents: '**.ps1' 
     targetFolder:  'C:\Test\Scenarios'
     cleanTargetFolder: false
     overwrite: true
     failOnEmptySource: false
     flattenFolders: true

 - task: SSH@0
   inputs:
   sshEndpoint: 'Dev SSH service'
   runOptions: 'commands'
   commands: 'C:\Test\Scenarios\test.ps1'
   readyTimeout: '20000'
Sign up to request clarification or add additional context in comments.

1 Comment

Since you have a workaround, you could mark your own answer to improve this ticket.
0

I know this is an old post but I just came across this same issue and thought I would post the fix that worked for me.

I am using a PowerShell script and I have configured my windows target machine to default the SSH shell to be PowerShell.

The error above comes from the script trying to remove windows line endings here: link (Line 219)

To fix this issue:

RunOptions should be changed from "Inline" to "Comands" The inline node should become commands

From:

- task: SSH@0
    inputs:
        sshEndpoint: YOUR_SSH_ENDPOINT_HERE
      runOptions: inline
      inline: | 
        Write-Output 'Hello, World!'
    displayName: Hello world

To:

- task: SSH@0
    inputs:
        sshEndpoint: YOUR_SSH_ENDPOINT_HERE
      runOptions: commands #<- changed this
      commands: | #<- changed this
        Write-Output 'Hello, World!'
    displayName: Hello world

Edit: This will break with multi line statements that need to share variables. Trying to use the ssh task for a batch/powershell target will create a headache, PowerShellOnTargetMachines@3 or even just a powershell task + New-PSSession -ComputerName xxx is the best way around this.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.