@Anandharaj Thanks for the response. So, for YAML pipelines, the way this works is slightly different. Unlike a normal variable, secret variables are not automatically decrypted into environment variables for scripts. You need to explicitly map secret variables. Check this article for more details.
I suspect you may have missed mapping the PAT explicitly to an env variable. Here is the complete set of steps you'd need to follow to make this work:
- Set secret variables in the pipeline settings UI for your pipeline.
a. Go to the Pipelines page, select the appropriate pipeline, and then select Edit.
b. Locate the Variables for this pipeline.
c. Add or update the variable AZURE_DEVOPS_EXT_PAT
.
d. Select Keep this value secret to store the variable in an encrypted manner.
e. Click OK to add the variable and Save changes.
- To use this secret variable in your script, you must explicitly map it as an environment variable. env:
AZURE_DEVOPS_EXT_PAT: $(AZURE_DEVOPS_EXT_PAT)
Here is the complete pipeline yml for your reference:
trigger:
- main
pool:
vmImage: ubuntu-latest
steps:
- bash: |
# Write your commands here
echo 'Hello world'
az devops project list
env:
AZURE_DEVOPS_EXT_PAT: $(AZURE_DEVOPS_EXT_PAT)
displayName: 'Azure DevOps Projects List'
Hope this helps. Please check and let us know if you have further questions.
----------
If an answer is helpful, please "Accept answer" and/or "Up-Vote" which might help other community members reading this thread.