azure - 在远程计算机上运行 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 = 命令执行它。
- 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'
推荐阅读
- c# - 十进制类型在 .ASP.net Core Razor 绑定中失去精度
- javascript - 使用 ngx-filter-pipe 过滤多个值
- javascript - 反应中时间线组件中步骤的单击应设置为活动状态并更改时间线颜色
- python - django.db.utils.IntegrityError:NOT NULL 约束失败:new__users_personal_detail.husband_adhaarcopy
- c# - 如何检查对象类型变量是否为空?
- android - 将 Gradle 升级到 3.6.0 后找不到本机库
- css - 通过Angular中的插值将css应用于打字稿变量的某些部分
- php - 根据数据库中的单选按钮值显示 div
- python - groupby 表 Python Pandas 有问题吗?
- java - 通知安卓 (FCM)