0

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

Tofuburger
  • 80
  • 1
  • 6
  • As an option, the Gates feature would work at the Stage level, but not at the Task level. Worth checking out. – Dave Skender May 14 '20 at 07:03
  • @Leo Liu-MSFT: Regarding your suggestion, the prerequesite is .NET 4.7.2 on the agent server. It is installed and now I'm waiting for the reboot this night. – Tofuburger May 15 '20 at 12:32
  • I tried some workaround with "Inline Powershell" Tasks: **1st task:** `if (!(Test-Connection -ComputerName "winsfaaly2.munichre.com" -BufferSize 16 -Count 4 -Quiet -ErrorAction 0)) { Write-Output "##vso[task.setvariable variable=VMIsRunning;isSecret=false;isOutput=true]True" Write-Output "True" } else {...}` **2nd task** is skipped with following message: _"Evaluating: and(succeeded(), eq(variables['VMIsRunning'], 'True')) Expanded: and(True, eq(Null, 'True')) Result: False"_ For second task I used `and(succeeded(), eq(variables['VMIsRunning'], 'True'))` as condition – Tofuburger May 15 '20 at 12:49

1 Answers1

1

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.

Leo Liu
  • 71,098
  • 10
  • 114
  • 135
  • This doesn't work for me : ( I tried to just set the variable in Script1 like this: `Write-Output "##vso[task.setvariable variable=VMIsRunning;isSecret=false;isOutput=true]True"` Then Script two with custom condition `and(succeeded(), eq(variables['VMIsRunning'], 'True'))` is skipped with following message: `Evaluating: and(succeeded(), eq(variables['VMIsRunning'], 'True')) Expanded: and(True, eq(Null, 'True')) Result: False` Sorry, seems like I'm to stupid to get the formatting right... – Tofuburger May 18 '20 at 12:39
  • @Tofuburger, That because you are not use the correct scripts, it should have a space before `isoutput = true`, `isSecret=false; isOutput=true`. – Leo Liu May 28 '20 at 09:36
  • Thanks a lot! That was the solution. It now works like a charm – Tofuburger May 29 '20 at 13:42