azure-powershell icon indicating copy to clipboard operation
azure-powershell copied to clipboard

Az Powershell throwing exception in DevOps release pipeline

Open matendie opened this issue 6 years ago • 6 comments

There is an exception thrown while executing New-AzAdServicePrincipal in Azure release pipeline, while same command ran from local machine succeeds without any issues...

$Password = "somepasswordhere"

Import-Module -Name Az.Resources # Imports the PSADPasswordCredential object

$credentials = New-Object Microsoft.Azure.Commands.ActiveDirectory.PSADPasswordCredential -Property @{StartDate=Get-Date; EndDate=Get-Date -Year 2124; Password=$Password}

$sp = New-AzAdServicePrincipal -DisplayName 'principalName' -PasswordCredential $credentials

Error in Azure release pipeline: 2020-07-29T14:03:54.0700833Z ##[error]Resource not found for the segment 'me'. 2020-07-29T14:03:54.1932824Z ##[error]PowerShell exited with code '1'.

matendie avatar Jul 29 '20 15:07 matendie

@matendie , In DevOps, I believe you connect Azure using service principle. Could you try the same service principle in your local code?

dingmeng-xue avatar Jul 30 '20 00:07 dingmeng-xue

@dingmeng-xue Yes, it does run using a service principal, I thought about it, but the exception doesn't say anything about permissions. I will see if I can get its password reset and use it to run it from local machine.

matendie avatar Jul 30 '20 12:07 matendie

OK, I logged in to Azure using my service principal and got the same error as in release pipeline. So I guess there is something wrong with the Principal? What is wrong though? How can I tell what needs to be fixed?

My personal account, which works, has only one role "Application administrator | Assignments" So does this Service Principal that I'm using for release "Application administrator | Assignments"

There is no known to me difference between them.

New-AzAdServicePrincipal : Resource not found for the segment 'me'. At line:14 char:7

  • $sp = New-AzAdServicePrincipal -DisplayName "$RealmMgrWebName$Identit ...
    • CategoryInfo : InvalidArgument: (:) [New-AzADServicePrincipal], Exception
    • FullyQualifiedErrorId : Microsoft.Azure.Commands.ActiveDirectory.NewAzureADServicePrincipalCommand

matendie avatar Jul 30 '20 15:07 matendie

My understanding is you need to go to your SP on Portal. Then, go to API permission, add application permission around Azure Active Directory Graph (such as Application.ReadWrite.OwnedBy), grant permission. If you still meet problem, please contact Azure support. We have limited knowledge on this area.

dingmeng-xue avatar Jul 31 '20 04:07 dingmeng-xue

dingmeng-xue Thank you for that info, I will try it!

matendie avatar Jul 31 '20 14:07 matendie

Close this issue now. Please contact us if you have further question.

dingmeng-xue avatar Aug 28 '20 08:08 dingmeng-xue