azurepowershellazure-devopsvirtual-machinecicd

Environment Azure Devops - error on adding a new VM


I am trying to add a new resource to an existing environment. I already have multiple vm resources in it. But I am getting an error in adding a new on premise VM to it.

I run the powershell in the vm in admin mode. I get the script from devops when I click on Add New Resource to an existing Environment and select VM. ON executing it in VM's powershell which I want added as the resource creates a folder A2 in C:/azagent and then asks for tag and soon as I provide Tag value it returns the following error:

Error reported in diagnostic logs. Examine the log for more information.
    – C:\azagent\A2\_diag\Agent_20240729-073104-utc.log
Failed to add virtual machine resource. Linked environment pool is null.
Error adding agent. Try again or press CTRL+C to exit.

I went through logs saw a few Key not found messages and tried to install Java in the VM even after it I do not see any change in the error.


Solution

  • According to Manage VM resources in environments, you need to satisfy the following prerequisites.

    • Project Administrator or Build Administrator permissions in the Azure DevOps project that contains the environment.
    • Administrator role for the deployment pool, or set of target servers available to the organization.

    The problem may be caused by insufficient permissions in your target Environment and Deployment pool. You can grant your account Administrator Role.

    1. Environment permission

      • Assign your account Project Administrator or Build Administrator role of your target project.

      • Or assign your account Administrator role of your target Environment.
        Go to Environments -> Select your target environment -> More actions -> Security -> Add user -> Search and select your account and assign Administrator role.

      enter image description here

    2. Deployment pool permission

      Find the environment pool in the environment URL.

      enter image description here

      Go to Organization Settings -> Deployment Pools -> Find your pool based on the environment id -> More actions -> Security -> Assign your account Administrator role.

      enter image description here

    After that, copy a new registration script and check if it works as expected.