Azure DevOps NPM身份验证任务终点

发布于 2025-02-09 23:35:00 字数 1514 浏览 2 评论 0 原文

我目前正在尝试在我的Azure DevOps管道中运行“ NPMauthenticate”任务,但是当“ customEndpoint”是一个可变化时,似乎正在遇到问题。如果我将相同的服务连接名称与参数传递在一起,但在管道中的其他位置时,它似乎可以正常工作。

破裂:

      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)'

当我尝试运行此操作时,我会在Azure DevOps中得到以下错误:

在解析管道yaml时遇到错误: 作业create_files:步骤输入customendpoint引用服务连接$(npm_endpoint),找不到。服务连接不存在或未授权使用。有关授权详细信息,请参阅 https://aka.ms/yamlauthz。

如果我将customEndpoint设置为以与完全相同的值传递的参数,则可以正常工作。

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

我在这里可能做错了什么,还是有人看到这样的事情?

编辑放入调试步骤以打印变量。运行时,它显示正确的值。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

北座城市 2025-02-16 23:35:00

原因:

简单地说,现在不支持。

您正在使用运行时变量。

但是运行时间变量不支持服务连接或Azure订阅。该变量将在运行时间初始化。

您可以按照下面的方法进行使用以使用不同的服务连接:

但仍然需要点,在管道运行之前,参数会扩展,硬码不可避免,这是设计。

在此官方文件中也很明显:

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

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

書生途 2025-02-16 23:35:00

您正在设置您的变量,例如 echo“ ## vso [task.setVariable variable = npm_endpoint]示例endendpointname“ ”,它将“在运行时进行处理”。

但是,您正在尝试使用该变量'$(npm_endpoint)',该变量将“在任务运行之前在运行时进行处理”。

您正在尝试在设置变量之前使用。

有关更多详细信息,请参见在此页面上了解可变语法 https://learn.microsoft.com/en-us/azure/azure/devops/devops/pipelines/process/process/variables? 2cbatch

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文