gog
gog

Reputation: 13008

Deploying and running .exe files using Azure Pipelines

I´m struggling to make my MultiStage pipelines to run a .exe file in a hosted agent running in a Azure VM.

My .yaml file is:

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

This VM is on the azure pipelines Environment. After I run this pipeline, the folder is downloaded into the VM, but I cannot find how to automate the execution of the output .exe file in this folder. I think the way is to create a job with a task to do it, but I cannot figure out how to set the agent installed on the VM to run this task.

How can I do that?

Upvotes: 2

Views: 6849

Answers (2)

starian chen-MSFT
starian chen-MSFT

Reputation: 33738

You could specify tasks in strategy: Deployment job For example:

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'

For this YAML pipeline, I publish all files in pipeline workspace to artifact in build stage, then this artifact will be download to target virtual machine of vm1 environment in deploy stage (folder name will be {stage name}.{job name}), then run command line task to get a file's content. (The script and command line tasks will be run on that virtual machine)

Upvotes: 2

Krzysztof Madej
Krzysztof Madej

Reputation: 40939

If I understood you correctly, you want to execute your artifact file which was deployed to VM.

I think that PowerShell on Target Machines task should do the job for you. Yoy can write simple inline script to exeute your file. However, you need to have remoting confogured on VM. This article may help you with this.

Upvotes: 2

Related Questions