1

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 https://aka.ms/yamlauthz.

If I set the customEndpoint as a parameter being passed in with the exact same value it works fine.

jobs:
  - job: Create_Files
    displayName: Create Files
    steps:
    - task: npmAuthenticate@0
      inputs:
        workingFile: '${{ parameters.npmc_file }}'
        customEndpoint: '${{ parameters.npm_endpoint }}'

Is there something I might be doing wrong here or has anybody seen anything like this?

EDIT Put in Debug step to print variable. When run it shows the correct value.

2
  • How are you setting the variable? Can you include that? Commented Jun 23, 2022 at 16:30
  • @ddastrodd on the broken run? Its here - echo "##vso[task.setvariable variable=npm_endpoint]ExampleEndpointName" Commented Jun 23, 2022 at 16:36

2 Answers 2

1

Reason:

Simply say, not support now.

You are using a runtime variable.

But run time variables aren't supported for service connection OR azure subscription. The variable will get initialized at the run time.

https://github.com/microsoft/azure-pipelines-tasks/issues/10376#issuecomment-514477023

You can follow below method to use different service connection:

https://stackoverflow.com/a/57520153/6261890

But still need point that, parameters are expanded just before the pipeline runs, hardcode the specific service connection is unavoidable, this is by design.

Also clearly in this official document:

https://learn.microsoft.com/en-us/azure/devops/pipelines/library/service-endpoints?view=azure-devops&tabs=yaml#use-a-service-connection

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

1

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://learn.microsoft.com/en-us/azure/devops/pipelines/process/variables?view=azure-devops&tabs=yaml%2Cbatch.

3 Comments

I have read this and still can't see what I'm doing wrong here. It says to do what I'm doing. To confirm, I created a task in between when the variable is set and when I try to use it and ran an 'echo $(npm_endpoint)' and it prints the correct value.
Can you include that in your code snippet? Maybe that will help us spot the issue.
Edited code snippet to show debug step where when run shows the variable value.

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.