0
votes

I have a service connection created for Azure Repos in a separate Azure DevOps org using a PAT.

I would like to be able to access that PAT from a PowerShell script in my pipeline yml since that same PAT has access to a nuget feed in the external org as well and I want to restore a package using that PAT.

Is there any way to do this? Or do I need to create a variable with that same PAT and store the token twice?

1

1 Answers

0
votes

Is there any way to do this? Or do I need to create a variable with that same PAT and store the token twice?

We can't access value of specific PAT via reading the service connection which uses the PAT for authorization. As the only way we use service connection is to copy the connection name/ID into pipeline as a value.

What's more, PAT can only be obtained and saved directly when you create it. After that you can only get PAT from where you saved, and you cannot find it from anywhere in Azure DevOps.

If you want to use that PAT in pipeline, you can save it in a variable group as a secret variable.

Here is the detailed steps:

1.Go to Pipelines -> Library -> Create a variable group -> Add a variable and change its type to secret -> Save.

2.Add the variable group to variables in YAML.

variables:
  - group: {variable group}

Then you can get the value of PAT by PowerShell scripts.