I am currently trying to run the 'npmAuthenticate' task within my Azure DevOps pipeline but seem to be running into an issue when the 'customEndpoint' is a set varaible. It appears to work just fine if I pass the same Service Connection Name in as a parameter but not when setting as a variable else where in the pipeline.
Broken:
jobs:
- job: Create_Files
displayName: Create Files
steps:
- task: Bash@3
displayName: Setting npm endpoint
inputs:
targetType: 'inline'
script: |
echo "##vso[task.setvariable variable=npm_endpoint]ExampleEndpointName"
- task: Bash@3
displayName: Debugging step to print variable
inputs:
targetType: 'inline'
script: |
echo "Printing npm endpoint - $(npm_endpoint)"
- task: npmAuthenticate@0
inputs:
workingFile: '${{ parameters.npmc_file }}'
customEndpoint: '$(npm_endpoint)'
When I try to run this I get the following error within Azure DevOps:
Encountered error(s) while parsing pipeline YAML: Job Create_Files: Step input customEndpoint references service connection $(npm_endpoint) which could not be found. The service connection does not exist or has not been authorized for use. For authorization details, refer to
CodePudding user response:
You are setting your variable like this echo "##vso[task.setvariable variable=npm_endpoint]ExampleEndpointName"
and it will "get processed during runtime".
But you are trying to use that variable like this '$(npm_endpoint)'
which will "get processed during runtime before a task runs".
You are trying to use the variable before it is set.
See Understand variable syntax on this page for more details: https://docs.microsoft.com/en-us/azure/devops/pipelines/process/variables?view=azure-devops&tabs=yaml,batch.