Gregory Sloan
Gregory Sloan

Reputation: 23

Is it possible to have an Azure hosted build agent persist between pipeline stages

I have a pipeline with 2 stages - a build/test stage, and a Teardown stage that cleans up external resources after the build/test stage. The teardown stage depends on some state information that gets generated in the build/test stage. I'm trying to use Azure hosted agents to do this. The problem is that the way I have it now, each stage deploys a new agent, so I lose the state I need for the teardown stage.

My pipeline looks something like this:

trigger:
- master

stages:
- stage: Build_stage
  jobs:
  - job: Build_job
    pool:
      vmImage: 'ubuntu-latest'
    steps:
    - task: InstallSomeTool@
    - script: invoke someTool
    - script: run some test

- stage: Teardown_stage
  condition: always()
  jobs:
  - job: Teardown_job
    pool:
      vmImage: 'ubuntu-latest'
    steps:
    - script: invoke SomeTool --cleanup

The teardown stage fails because it's a brand new agent that knows nothing about the state created by the previous invoke someTool script.

I'm trying to do it this way because the Build stage creates some resources externally that I want to be cleaned up every time, even if the Build stage fails.

Upvotes: 2

Views: 451

Answers (1)

Mengdi Liang
Mengdi Liang

Reputation: 19026

Is it possible to have an Azure hosted build agent persist between pipeline stages?

No, you can't. The hosted agent are all randomly assigned by server. You could not use any script or command to specify a specific one.

Since you said that the Build_Stage will create some resources externally, so that you want to execute clean up to clean it.

In fact, for this, you can execute this clean up command as the last steps in Build_Stage. If this, whether using hosted or private agent will not affect what you want.

Upvotes: 1

Related Questions