gpt4 book ai didi

Azure 管道 BatchScript 任务未在其部署到的计算机上运行脚本

转载 作者:行者123 更新时间:2023-12-03 05:40:10 25 4
gpt4 key购买 nike

我有一个 azure 部署管道,可以使用此任务将文件复制到我的帐户上托管的 azure 虚拟机:

- task: AzureFileCopy@3
inputs:
SourcePath: '$(Build.ArtifactStagingDirectory)'
azureSubscription: 'qa-serverside-snapshots'
Destination: 'AzureVMs'
storage: 'serversidesnapshotsdiag'
enableCopyPrerequisites: true
resourceGroup: 'SERVERSIDE-SNAPSHOTS'
vmsAdminUserName: $(username)
vmsAdminPassword: $(password)
TargetPath: 'C:\Git\serverside-snapshots'

问题是我遇到了与无法写入文件有关的错误,因为该文件正在由计算机上运行的服务使用。所以我想做的是运行一个bat脚本来停止azure VM上的服务。这是我的尝试:

- task: BatchScript@1
inputs:
filename: '$(Build.SourcesDirectory)\stopPM2.bat'
workingFolder: 'C:\Git\serverside-snapshots'

“stopPM2.bat”字面上只包含pm2 stop myservice。问题是,当 bat 文件运行时,我收到此错误:

C:\Git\serverside-snapshots>pm2 stop myservice
'pm2' is not recognized as an internal or external command,
operable program or batch file.
##[error]Process completed with exit code 1.

我肯定在我要部署到的服务器上安装了 PM2。看起来bat文件实际上并没有在我尝试部署到的VM上运行,而是在管道正在运行的临时VM上运行。所以我的问题是,如何让 bat 脚本在我要部署到的虚拟机上运行,​​以便我可以在复制文件之前停止服务?

最佳答案

BatchScript在构建代理上运行

您需要使用目标计算机上的 PowerShell目标计算机上的 SSH 来调用远程计算机上的某些内容。

关于Azure 管道 BatchScript 任务未在其部署到的计算机上运行脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59411102/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com