vfabing / AzureVm

Azure DevOps Pipelines extension for starting and stopping Azure VM
https://marketplace.visualstudio.com/items?itemName=vfabing.AzureVirtualMachineManagerTask
MIT License
3 stars 3 forks source link

stop vm not working with the azure pipeline #15

Open piyushsachdeva2000 opened 3 years ago

piyushsachdeva2000 commented 3 years ago

Hi, I have created an Azure DevOps pipeline for start/stop VM using service connection. start task is working fine however, stop task getting failed with the below error:

2020-10-07T17:45:43.4683405Z ##[debug][POST]https://login.windows.net/***/oauth2/token/ 2020-10-07T17:45:43.7302725Z ##[debug][POST]https://management.azure.com/subscriptions/xxxxx/resourceGroups/resorucegroupname/providers/Microsoft.Compute/virtualMachines/vmname/powerOff?api-version=2016-03-30 2020-10-07T17:45:43.9428145Z ##[debug]Processed: ##vso[task.logissue type=error;code=AuthorizationFailed;] 2020-10-07T17:45:43.9429619Z ##[debug]task result: Failed 2020-10-07T17:45:43.9430598Z ##[error]Could not stop vmname 2020-10-07T17:45:43.9432145Z ##[debug]Processed: ##vso[task.issue type=error;]Could not stop vmname 2020-10-07T17:45:43.9441902Z ##[debug]Processed: ##vso[task.complete result=Failed;]Could not stop vmname 2020-10-07T17:45:43.9442570Z ##[debug]Stopping-error: [object Object]

Below is the pipeline snippet

trigger:

pool: vmImage: 'vs2017-win2016' name: Azure Pipelines

steps:

vfabing commented 3 years ago

Hi @piyushsachdeva2000,

Thank you very much for reaching to me !

I just made a quick test with the following yaml pipeline :

# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml

trigger:
- master

pool:
  vmImage: 'ubuntu-latest'

steps:
- script: echo Hello, world!
  displayName: 'Run a one-line script'

- task: AzureVirtualMachineManagerTask@1
  inputs:
    Action: 'Stop VM'
    azureSubscription: 'MY AZURE SUBSCRIPTION(57dc3da4-8342-4106-ju41-02a6da83ab0e)'
    ResourceGroupName: 'rg-my-azure-vm-Build'
    VmName: 'vmBuild1'

but didn't get any error

image

Note: I also tried on the vs2017-win2016 image, but didn't get any error

What I would try :

piyushsachdeva2000 commented 3 years ago

Hey, Thank you very much for getting back to me so quickly! I tried to run via CLI and vm stop only seems to be working after the vm deallocate command. Is there any way you could add the vmstopwithdellocate option?

Regards, Piyush

vfabing commented 3 years ago

Hi Piyush,

Thank you for trying the mentioned scenarios,

Just to give you a little bit more insight of the Stop VM extension workflow :

By the way, my previous comment was a little off too, it should have been in fact:

As a workaround, could you try to use Azure CLI to stop and deallocate the VM and see if you get the same result?

Which should do the same job as the Start/Stop VM extension. My guess is if you run both of them, the Azure CLI tasks do the real job of stopping and deallocating the VM, and then the extension send the same signals, but in reality do nothing since the VM should be already stopped and deallocated.

To be honest, if the Start/Stop VM extension is not working for you (which make me deeply saddened of course...) but the Azure CLI is, your best bet is to stick with the Azure CLI...

In any case, thank you very much for taking the time to fill a bug report and very sorry if the extension is not working for you m( )m