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

时间:2019-12-19 13:49:01

标签: azure batch-file azure-devops azure-pipelines

我有一个Azure部署管道,可以使用以下任务将文件复制到托管在我的帐户上的Azure VM:

- 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脚本在要部署到的VM上运行,以便在复制文件之前可以停止该服务?

1 个答案:

答案 0 :(得分:1)

BatchScript在构建代理上运行

您需要使用PowerShell on Target MachineSSH on Target Machine来调用远程计算机上的某些内容。

相关问题