微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在远程计算机上运行 PowerShell 脚本在 Azure Devops 中不起作用

如何解决在远程计算机上运行 PowerShell 脚本在 Azure Devops 中不起作用

我正在尝试通过 ssh 在远程机器上运行 Powershell 脚本。我已经配置了 Azure 版本,但出现了一个非常奇怪的错误

这是我的配置文件的样子

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'

这是我的 Powershell 脚本的样子:

Write-Host "Hello,World!"

远程计算机通过 PowerShell 配置了 ssh。

我收到如图所示的错误

enter image description here

转录:

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.

解决方法

我解决了这个问题。我创建了一个 System.Debug 变量。我看到了 SSH0 是如何工作的,最后我只是将脚本复制到远程机器并通过设置 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'

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?