Declarative pipeline error

Hi everyone I’m trying to use declarative pipeline that

  1. connects to private github repo (no error authenticating jenkins on github PAT: private access token)
  2. pipeline file has the instructions to jenkins
  3. there are 2 powershell script on repo:
  • Connect-ToMgGraph.ps1: with parameters connects to Microsoft graph api
  • script 1: has get-mguser ( graph API command to list users )

Jenkins setup:
Jenkins 2.470
on Azure VM Linux (ubuntu 24.04), Standard B2s (2 vcpus, 4 GiB memory)
running on Docker version 27.0.3, build 7d4bcd8

I can run the script to authenticate on Microsoft graph using parameters Connect-ToMgGraph.ps1

do I need to break into stages?

Then script2 that runs right after the “Connect-ToMgGraph.ps1” fails saying must authenticate

agent { label 'node1-windows11-surface' } stages { stage('hello') { steps { powershell """ powershell.exe -File \" Connect-ToMgGraph.ps1 \" -NoNewWindow -Wait -entraapp -AppId 'xxx' -Tenant 'letsintune.com' -AppSecret 'xxx' write-output "Waiting....." powershell.exe -File \"Script1.ps1\" -NoNewWindow -Wait """ } } } }

console output

Waiting…
Running Script 1

powershell.exe : get-mguser : Authentication needed. Please call Connect-MgGraph.

That’s because you are passing both files as parameters to “powershell.exe” which creates two separate PowerShell sessions. See -File description here Powershell.exe - PowerShell - SS64.com .

You could try using -NoExit but better approach would be to run files directly, without calling additional PowerShell.exe session.