Search code examples
azureazure-pipelinesazure-pipelines-release-pipelineazure-pipelines-tasks

Azure Release Pipeline - Only run agent job if VM is available


I would like to create an agent job task in an Azure Release Pipeline, which will only run if the affected VM is up and running. I had a peek into the 'Azure Pipeline Conditions', but it seems there is no such thing as 'checking for server status'. Also did not found a Task Template for checking the VM status. Therefore I cannot create an Output Variable beforehand and use THIS in a condition. Thanks a lot in advance!

BR Denis


Solution

  • Azure Release Pipeline - Only run agent job if VM is available

    Indeed, just as you know that, there is not such condition or task to check the VM status at this moment.

    As workaround, we could create a scripts to check the VM status, like powershell:

    PS C:\> Get-VM -ComputerName Server1 | Where-Object {$_.State -eq 'Running'}
    

    Get-VM

    Then, sets variable with different value based on the VM status:

    Write-Output "##vso[task.setvariable variable=VMIsRunning]True"
    

    OR

    Write-Output "##vso[task.setvariable variable=VMIsRunning]Flase"
    

    And add custom conditions in the next steps in the build pipeline:

    and(succeeded(), eq(variables['VMIsRunning'], 'True'))
    

    Hope this helps.