0
votes

Been working with using Azure DevOps to automate some PowerShell scripts against SharePoint Online. From what I understand, my first step needs to be getting authenticated against that tenant. So here's what I've got so far:

trigger: - master

pool: vmImage: 'windows-latest'

steps:

  • powershell: Install-Module -Name Microsoft.Online.SharePoint.PowerShell -RequiredVersion 16.0.8029.0 -force displayName: 'Install SP Online PowerShell'

  • powershell: $cred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $env:USERNAME, $(convertto-securestring $env:PASSWORD -asplaintext -force) displayName: 'form the credentials var from previous vars'

  • powershell: Connect-SPOService -Url https://$env:ORG-admin.sharepoint.com -Credential $cred displayName: 'connect to Tenant'

Environment variables username, password, and org are defined at the pipeline and seem to be working correctly (as in, I was getting different errors before deploying those). Now, I get to the final step and it just runs forever until I cancel it. It's as if it's getting some prompt on Connect-SPOService that, of course, I can't see, and so I can't respond to.

There are no errors to react to, just sits and spins and doesn't finish. My last error was that connect-sposervice wasn't a recognized cmdlet. To resolve that, I worked on my install-module command and got that resolved, so it seems like it's running that command properly now (no errors).

I can run all the same powershells from my local machine and get there without prompts or having to enter anything extra.

Anyone have any ideas?

Thanks!

1
Apart from the microsoft-hosted agent, what's the result if you run the pipeline with a self agent. You can install one self agent in your machine, and call it to run same pipeline to check if hosted agent lacks some components this process needs.LoLance
Hi friend, is there any update for this issue?LoLance

1 Answers

0
votes

It seems that you're following this document to connect to Sharepoint online.

Note: When prompted with the Windows PowerShell credential request dialog box, type the password for the SharePoint Online SharePoint administrator account.

When using Microsoft-hosted agent to run the PowerShell task, we can't access the UI to enter password in dislog box. So this is not supported way.

Instead, you may get help from these two documents: Installing the Office 365 CLI and Connecting to SharePoint Online.