如何解决在远程计算机上运行 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。
我收到如图所示的错误
转录:
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 举报,一经查实,本站将立刻删除。