Azure DevOps NPM身份验证任务终点
我目前正在尝试在我的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 }}'
我在这里可能做错了什么,还是有人看到这样的事情?
编辑放入调试步骤以打印变量。运行时,它显示正确的值。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
原因:
简单地说,现在不支持。
您正在使用运行时变量。
但是运行时间变量不支持服务连接或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
您正在设置您的变量,例如
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.