Forum Discussion
Azure DevOps + Deployment Pipeline Integration Error
- 9 months ago
I would advise looking to try this in a YAML pipeline instead, using the PowerShell script provided by Microsoft instead of the task.
I have a post that covers how to do that below:
https://www.kevinrchant.com/2024/06/11/update-fabric-deployment-pipeline-stages-with-deploymentpipelines-deployall-and-yaml-pipelines/I hope this helps, if so give it some kudos and/or mark it as the solution.
Thanks Kevin, I have been trying to implement this over the past week, just the part that deploys Test to Production. I seem to be stuck though; the second PowerShell script succeeds but outputs the following error: Failed to deploy. Error reponse: {"requestId":"[ID]","errorCode":"InvalidToken","message":"Access token is invalid"}
I set up the authentication with the key vault connection in the variable group as you recommended, and passed the name of the secret into the first PS script, which succeeds. But then it seems like the connection isn't retained when the second script runs. Any suggestions?
How are you authenticating?
One error I see is when authenticating with PowerShell, because sometime s when using PowerShell in ADO you require quotes.
Try replicating what you are trying to do locally first in PowerShell, if that works test with and without quotes around your secret value.
- LeifB9 months agoAdvocate II
Just a follow-up for anyone who comes across this in the future - we were able to use Kevin's solution, except instead of authenticating in a separate PowerShell step in the pipeline, we added this into the DeploymentPipelines-DeployAll script. We had to pass additional parameters into the script, but the only one not mentioned in Kevin's solution was the Subscription ID. This is the updated SetFabricHeaders function:
function SetFabricHeaders() { # Login to Azure #Connect-AzAccount | Out-Null $SecureStringPwd = ConvertTo-SecureString $SPNSecret -AsPlainText -Force $pscredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $servicePrincipalId, $SecureStringPwd Connect-AzAccount -ServicePrincipal -Credential $pscredential -Tenant $tenantId -Subscription $subscriptionId # Get authentication $fabricToken = Get-AzAccessToken -ResourceUrl $global:resourceUrl $plainToken = [Runtime.InteropServices.Marshal]::PtrToStringAuto( [Runtime.InteropServices.Marshal]::SecureStringToBSTR($fabricToken.Token) ) $global:fabricHeaders = @{ 'Content-Type' = "application/json" 'Authorization' = "Bearer $plainToken" } } - LeifB9 months agoAdvocate II
I used what was in your script, the variables are passed via variable groups in the library as you recommended:
$SecureStringPwd = ConvertTo-SecureString $(SPNSecret) -AsPlainText -Force$pscredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $(servicePrincipalId), $SecureStringPwdConnect-AzAccount -ServicePrincipal -Credential $pscredential -Tenant $(tenantId)I just tried copying everything into PS locally and got the same error as I did in ADO. I also tried adding quotes around the $(SPNSecret) in ADO but there was no change. In both cases, it seems to authenticate with no issues, as it returns the subscription name and tenant ID in the output, but the step to actually get the access token seems to fail.