vsts-npm-auth无法在VSTS构建上获取身份验证令牌 [英] vsts-npm-auth can't get authentication token on VSTS build

查看:168
本文介绍了vsts-npm-auth无法在VSTS构建上获取身份验证令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 vsts-npm-auth 来获取VSTS软件包存储库的身份验证令牌.在我的开发机器上,我可以运行命令

I'm attempting to use vsts-npm-auth to get the authentication token for our VSTS package repository. On my development machine I can run the commands

npm install -g vsts-npm-auth vsts-npm-auth -config path-to-my\.npmrc

npm install -g vsts-npm-auth vsts-npm-auth -config path-to-my\.npmrc

,它成功为我提供了身份验证令牌.我现在正尝试在VSTS上重新构建它,因此我创建了Powershell脚本auth-vsts.ps1

and it succeeds in providing me with an authentication token. I'm now trying to recreate this as a build step on VSTS, so I create the powershell script auth-vsts.ps1

$npmrcFile = "$PSScriptRoot\path-to-my\.npmrc";
npm install -g vsts-npm-auth;
vsts-npm-auth -config $npmrcFile;

并将其添加为powershell任务.但是,任务失败,如下所示

and add it as a powershell task. However, the task fails as follows

2017-05-30T09:37:41.1082686Z ##[section]Starting: auth-vsts
2017-05-30T09:37:41.1092712Z ==============================================================================
2017-05-30T09:37:41.1092712Z Task         : PowerShell
2017-05-30T09:37:41.1092712Z Description  : Run a PowerShell script
2017-05-30T09:37:41.1092712Z Version      : 1.2.3
2017-05-30T09:37:41.1092712Z Author       : Microsoft Corporation
2017-05-30T09:37:41.1092712Z Help         : [More Information](https://go.microsoft.com/fwlink/?LinkID=613736)
2017-05-30T09:37:41.1092712Z ==============================================================================
2017-05-30T09:37:41.1112679Z ##[command]. 'd:\a\1\s\auth-vsts.ps1' 
2017-05-30T09:37:47.3792461Z C:\NPM\Modules\vsts-npm-auth -> C:\NPM\Modules\node_modules\vsts-npm-auth\bin\vsts-npm-auth.exe
2017-05-30T09:37:47.3792461Z C:\NPM\Modules
2017-05-30T09:37:47.3802239Z `-- vsts-npm-auth@0.25.0 
2017-05-30T09:37:47.3802239Z 
2017-05-30T09:37:47.3802239Z 
2017-05-30T09:37:47.3802239Z vsts-npm-auth v0.25.0.0 
2017-05-30T09:37:47.3802239Z -----------------------
2017-05-30T09:37:47.3802239Z Creating npmrcFile. Path: D:\a\1\s\.npmrc
2017-05-30T09:37:47.3802239Z Getting new credentials for source:https://our-domain/_packaging/SharedLib/npm/registry/, scope:vso.packaging_write vso.drop_write
2017-05-30T09:37:49.8729702Z Caught exception: The prompt option is invalid because the process is not interactive.
2017-05-30T09:37:49.8729702Z Parameter name: PromptType
2017-05-30T09:37:49.8729702Z Caught exception: The prompt option is invalid because the process is not interactive.
2017-05-30T09:37:49.8729702Z Parameter name: PromptType
2017-05-30T09:37:49.8729702Z Couldn't get an authentication token for //our-domain/_packaging/SharedLib/npm/registry/:_authToken.
2017-05-30T09:37:50.1769711Z ##[error]Process completed with exit code 1.
2017-05-30T09:37:50.1809715Z ##[section]Finishing: auth-vsts

该错误没有说明为什么无法获得凭据.任何想法为什么会这样?

The error gives no indication as to why it can't obtain the credentials. Any ideas why this might be?

推荐答案

该错误确实表明了为什么无法获得凭据:

The error did indicate why it cannot obtain the credentials:

The prompt option is invalid because the process is not interactive.

这可能是由于构建代理未在交互模式下运行而导致无法提示凭据对话框.如果您使用的是Hosted Build Agent,则该构建代理将作为服务运行,并且无法更改为交互模式.

This could be caused by the build agent does not run in interactive mode which make the credential dialog cannot be prompted. If you are using Hosted Build Agent, the build agent is run as service and there isn't any way to change to interactive mode.

但是,这里的问题是,如果要在构建步骤中使用提要,则在构建过程中提示凭据对话框没有意义,因为生成步骤无法自动输入所需的凭据.不确定环境中是否有特定要求,但是一般的工作流程应该将本地计算机中生成的.npmrc文件上传到源代码管理,以便npm可以使用文件中的auth令牌将软件包安装/发布到VSTS提要.

However, the issue here is that if you want to use the feed in a build step, it does not make sense to prompt a credential dialog during the build process since the build step cannot enter the required credential automatically. Not sure if there is any specific requirement in your environment, but the general workflow should be uploading the .npmrc file generated in your local machine to the Source Control so that npm can use the auth token in the file to install/publish packages to VSTS Feed.

这篇关于vsts-npm-auth无法在VSTS构建上获取身份验证令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆