In my release pipeline I have a powershell task, where I want to to invoke some custom git commands like git fetch
I'm getting
fatal: Cannot prompt because terminal prompts have been disabled.
fatal: could not read Password for 'https://[email protected]': terminal prompts disabled
How do I authenticate the agent?
I could you the same authentication as Agent in "Download Artifacts" task.
CodePudding user response:
Please check out this page on Microsoft Learn about using custom git commands in pipelines:
The trick from keeping signed-in is to use persistCredentials
steps:
- checkout: self
persistCredentials: true
This is usely done in the build phase when one or more repos are checked out.
In your case it's in the deployment phase Not sure if it will work in deployment as well...
Just out of curiosity... What is functionally in the repo? And why are you doing this in the deployment phase?
CodePudding user response:
It is failing because the git command line is waiting for entering credentials.
But an ADO pipeline already has a valid token in a pre-defined env variable System.AccessToken
Add -c http.extraheader="AUTHORIZATION: bearer $(System.AccessToken)"
(in cmd
syntax) at the beginning of your git command line (just after the git verb pull
)
The syntax could be a little different in powershell.
See https://learn.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=yaml#systemaccesstoken for predefined variables documentation and the exact transformation syntax.
In powershell it should be something like $env:SYSTEM_ACCESSTOKEN