1

In my powershell script, I call the following azure function:

az repos import create --git-source-url https://[email protected]/my-organisation/Templates/_git/$($Framework) --detect true --project $ProjectAlias --repository $ProjectAlias --requires-authorization

When running, it prompts the user for a Password/PAT token, e.g:

Git Password / PAT:

Is there a way to automatically pass the password/token to the user input without having to enter manually?

I attempted to pipe the value through, however this does not seem to work e.g

my-pat-token | az repos import create --git-source-url https://[email protected]/my-organisation/Templates/_git/$($Framework) --detect true --project $ProjectAlias --repository $ProjectAlias --requires-authorization

Is this both a) possible and then if so b) how can I do this?

1 Answer 1

3

There are two approaches you can use, both come courtesy from this nice blog post which you'll probably want to read, as it talks about a bunch of Azure Devops tasks.

  1. Use an environmental variable

These commands will check for the presence of an environmental variable and will use it instead of prompting.

To do this, set an environment variable called AZURE_DEVOPS_EXT_PAT to the value of your PAT. (More info on how these tokens work here from the Microsoft Docs)

# set environment variable for current process
$env:AZURE_DEVOPS_EXT_PAT = 'xxxxxxxxxx'

When you're automating things, just set this variable before running the Azure commands.

  1. Pipe the value in

I am not as big of a fan of this sort of approach but you can "echo out" the PAT value and pipe that into a command, which might work. IMHO this is more fragile and frunky and I wouldn't advise it.

$pat | az devops login
Sign up to request clarification or add additional context in comments.

1 Comment

perfect! that article contains a specific config key for repos import as it doesn't use the base login credentials. AZURE_DEVOPS_EXT_GIT_SOURCE_PASSWORD_OR_PAT

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.