Azure Devops:即使设置了NPM身份验证,也无法使用NPM专用注册表生成映像 [英] Azure Devops: Cannot Build an Image using NPM private registry even after setting NPM Authenticate

查看:45
本文介绍了Azure Devops:即使设置了NPM身份验证,也无法使用NPM专用注册表生成映像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

设置NPM身份验证后,我在npm安装上总是遇到错误.我想在映像构建过程中向我的npm私有注册表进行身份验证,并安装所需的所有依赖项.也许我误解了此身份验证过程的工作原理,但这是我正在做的事情:

I am always getting an error on npm install after setting NPM Authenticate. I would like to authenticate to my npm private registry during image build and install all the dependencies I need. Maybe I misunderstood how this authentication process works but this is what I am doing:

构建管道

我尝试从项目设置页面建立服务连接,如

I tried establishing a service connection from the project settings page as in Service connections for builds and releases

之后,我还按照但是这不起作用.这些是我得到的错误:

But this is not working. These are the errors I am getting:

"NPM身份验证"阶段:

During 'NPM Authenticate' phase:

[warning]找到并取代了所选.npmrc文件中的myregistry.pkgs.visualstudio.com注册表.从文件中删除凭据并将其存储在npm服务中而是连接(推荐),或删除npm Authenticate任务从您的版本中使用签入.npmrc的凭据.

[warning]Found and overrode credentials for the myregistry.pkgs.visualstudio.com registry in the selected .npmrc file. Remove credentials from the file and store them in an npm service connection instead (recommended), or remove the npm Authenticate task from your build to use credentials checked into an .npmrc.

在构建图像"阶段:

第4/7步:运行npm install --production --->在8724f713f1db中运行[91mnpm ERR!代码[0m [91m E404 [0m [91mnpm [0m [91mERR!404 [0m [91m不是找到:@ myregistry/service-logging @ latest npm ERR![0m [91m A完成该运行的日志可在以下位置找到:npm ERR!
/root/.npm/_logs/2018-09-11T04_20_00_513Z-debug.log [0m命令'/bin/sh -c npm install --production'返回非零代码:1[错误]命令'/bin/sh -c npm install --production'返回非零代码:1 [错误]/usr/local/bin/docker失败,返回代码:1 [section]完成:制作图片

Step 4/7 : RUN npm install --production ---> Running in 8724f713f1db [91mnpm ERR! code[0m[91m E404 [0m[91mnpm [0m[91mERR! 404[0m[91m Not Found: @myregistry/service-logging@latest npm ERR![0m[91m A complete log of this run can be found in: npm ERR!
/root/.npm/_logs/2018-09-11T04_20_00_513Z-debug.log [0mThe command '/bin/sh -c npm install --production' returned a non-zero code: 1 [error]The command '/bin/sh -c npm install --production' returned a non-zero code: 1 [error]/usr/local/bin/docker failed with return code: 1 [section]Finishing: Build an image

这是我的.npmrc文件:

This is my .npmrc file:

unsafe-perm=true
package-lock=false
registry=https://myregistry.pkgs.visualstudio.com/_packaging/myregistry/npm/registry/
always-auth=true
//myregistry.pkgs.visualstudio.com/_packaging/myregistry/npm/registry/:_authToken=${NPM_TOKEN}
//myregistry.pkgs.visualstudio.com/_packaging/myregistry/npm/:_authToken=${NPM_TOKEN}

这是我的Dockerfile:

And this is my Dockerfile:

FROM node:8.9-alpine

ARG NPM_TOKEN

WORKDIR /usr/src/srv/

COPY package.json package.json

COPY .npmrc .npmrc

RUN npm install --production

RUN rm -f .npmrc

COPY . .

EXPOSE 8080

CMD npm start

任何帮助我解除此问题的帮助将受到高度赞赏!谢谢!

Any help to unblock me from this issue will be highly appreciated! Thanks!

推荐答案

我终于通过删除.npmrc文件中的最后两行解决了管道中的此问题.最后一行引起了问题.完成NPM身份验证任务后,我的.npmrc文件被修改为:

I finally resolved this issue in my pipeline by removing the last two lines in my .npmrc file. the last line was causing an issue. After the NPM Authenticate task, my .npmrc file was being modified to:

unsafe-perm=true
package-lock=false
registry=https://myregistry.pkgs.visualstudio.com/_packaging/myregistry/npm/registry/
always-auth=true

//myregistry.pkgs.visualstudio.com/_packaging/myregistry/npm/:_authToken=${NPM_TOKEN}

//myregistry.pkgs.visualstudio.com/_packaging/myregistry/npm/registry/:username=VssToken
//myregistry.pkgs.visualstudio.com/_packaging/myregistry/npm/registry/:_password=***
//myregistry.pkgs.visualstudio.com/_packaging/myregistry/npm/registry/:email=VssEmail
//myregistry.pkgs.visualstudio.com/_packaging/myregistry/npm/registry/:always-auth=true

以某种方式,以下配置已被考虑,而NPM Authenticate插入的配置被忽略,从而导致管道错误:

Somehow, the following config was being taken into consideration and the config the NPM Authenticate inserted was being ignored, causing the pipeline error:

//myregistry.pkgs.visualstudio.com/_packaging/myregistry/npm/:_authToken=${NPM_TOKEN}

此外,由于NPM Authenticate会为您完成这项工作,因此无需添加以下行:

Also, no need to include the following line since NPM Authenticate will do the job for you:

//myregistry.pkgs.visualstudio.com/_packaging/myregistry/npm/registry/:_authToken=${NPM_TOKEN}

通过删除上面的行,此警告消失了:

By removing the line above, this warning disappeared:

[warning]找到并取代了所选.npmrc文件中的myregistry.pkgs.visualstudio.com注册表.从文件中删除凭据并将其存储在npm服务中而是连接(推荐),或删除npm Authenticate任务从您的版本中使用签入.npmrc的凭据.

[warning]Found and overrode credentials for the myregistry.pkgs.visualstudio.com registry in the selected .npmrc file. Remove credentials from the file and store them in an npm service connection instead (recommended), or remove the npm Authenticate task from your build to use credentials checked into an .npmrc.

因此,总而言之,只需将您的.npmrc文件保持如此简单:

So, to conclude, just keep your .npmrc file as simple as this:

unsafe-perm=true
package-lock=false
registry=https://myregistry.pkgs.visualstudio.com/_packaging/myregistry/npm/registry/
always-auth=true

Dockerfile一切都很好.

Everything was fine with the Dockerfile.

这篇关于Azure Devops:即使设置了NPM身份验证,也无法使用NPM专用注册表生成映像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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