使用Azure管道部署和运行.exe文件

gywdnpxw  于 2023-10-22  发布在  其他
关注(0)|答案(2)|浏览(103)

我正在努力使我的多级管道在Azure VM中运行的托管代理中运行.exe文件。
我的.yaml文件是:

trigger:
- develop

 stages:
  - stage: build
    displayName: Build
  jobs:
   - job: buildJob
     pool: 
       vmImage: 'ubuntu-16.04'
     variables:
       buildConfiguration: 'Release'  
 steps:
  - task: NuGetToolInstaller@1
    inputs:
      versionSpec: '5.5.0'

  - task: DotNetCoreCLI@2
    displayName: 'Dotnet Build $(buildConfiguration)'
    inputs:      
      command: 'build'
      arguments: '--configuration $(buildConfiguration)'
      projects: '**/TestProj.csproj'

  - task: DotNetCoreCLI@2
    displayName: "Publish"
    inputs:
      command: 'publish'
      publishWebProjects: false                    
      projects: '**/TestProj.csproj'
      arguments: '--no-restore --configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)'
      zipAfterPublish: false

  - task: PublishBuildArtifacts@1
    inputs:
      PathtoPublish: '$(Build.ArtifactStagingDirectory)'
      ArtifactName: 'drop'          
      publishLocation: Container

- stage: Release
   displayName: Release
   dependsOn: build
  jobs:      
   - deployment: AzureVMDeploy           
     displayName: agentDeploy
     environment:           
       name: AzureDeploy
       resourceName: vmName
       resourceType: VirtualMachine
       tags: develop

此虚拟机位于Azure管道Environment上。运行此管道后,文件夹被下载到VM中,但我无法找到如何自动执行此文件夹中的输出.exe文件。我认为方法是创建一个带有任务的作业来完成它,但我不知道如何设置安装在VM上的代理来运行此任务。
我怎么能这么做呢?

bvjxkvbb

bvjxkvbb1#

如果我理解正确的话,您希望执行部署到VM的工件文件。
我认为PowerShell on Target Machines task应该为你做的工作。你可以编写简单的内联脚本来执行你的文件。但是,您需要在VM上配置远程处理。This article可以帮助你。

7lrncoxx

7lrncoxx2#

您可以在策略中指定任务:部署作业例如:
YAML

stages:
- stage: build
  jobs:
    - job: buildJob
      pool:
        vmImage: 'Ubuntu-16.04'
      steps:
        - task: PublishPipelineArtifact@1
          inputs:
            targetPath: '$(Pipeline.Workspace)'
            publishLocation: 'pipeline'

- stage: deploy
  dependsOn: build
  jobs:
  - deployment: DeployWeb
    displayName: deploy Web App
    environment:
      name: vm1
      resourceType: virtualmachine
    strategy:
      runOnce:
        deploy:
            steps:
            - script: echo my first deployment
            - task: CmdLine@2
              inputs:
                script: 'more README.md'
                workingDirectory: '$(Pipeline.Workspace)/build.buildJob/s'

对于这个YAML管道,我在构建阶段将管道工作区中的所有文件发布到工件,然后在部署阶段将此工件下载到vm 1环境的目标虚拟机(文件夹名称为{stage name}.{job name}),然后运行命令行任务以获取文件的内容。(脚本和命令行任务将在该虚拟机上运行)

相关问题