我正在尝试使用npm publish
将 javascript 库发布到托管在 AWS Codeartifact 上的私有 NPM 存储库。
当我尝试npm publish
在本地机器上运行时,它可以正常工作。但是,当我尝试在 Jenkins 上运行它时,看起来该包正试图发布到 NPM 的包存储库而不是 AWS codeartifact,并且我收到以下错误:
> @company/package@0.2.2 prepare .
> npm run co:login
> @company/package@0.2.2 co:login /usr/src/components
> aws codeartifact login --tool npm --domain <DOMAIN> --repository <REPOSITORY>
Successfully configured npm to use AWS CodeArtifact repository <AWS_CODEARTIFACT_URL>
Login expires in 12 hours at 2020-12-08 11:15:37+00:00
npm notice
npm notice package: @company/package@0.2.2
npm notice === Tarball Contents ===
npm notice 2.9kB package.json
npm notice 1.6kB README.md
npm notice 268B dist/index.d.ts
npm notice === Tarball Details ===
npm notice name: @company/package
npm notice version: 0.2.2
npm notice package size: 2.1 kB
npm notice unpacked size: 4.8 kB
npm notice shasum: <SHASUM>
npm notice integrity: <INTEGRITY>
npm notice total files: 3
npm notice
npm ERR! code E404
npm ERR! 404 Not Found - PUT https://registry.npmjs.org/@company%2fpackage - Not found
npm ERR! 404
npm ERR! 404 '@company/package@0.2.3' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2020-12-08T00_20_19_949Z-debug.log
如果我了解AWS codeartifact 文档.npmrc
,它应该在我们运行aws codeartifact login
命令时设置正确的设置。我仍然不明白为什么它试图推送到 npm 注册表而不是 AWS。
这是我的 package.json:
{
"name": "@company/package",
"version": <VERSION>,
"main": "dist/index.js",
"module": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
"dist"
],
"dependencies": {...},
"scripts": {
"co:login": "aws codeartifact login --tool npm --domain <DOMAIN> --repository <REPOSITORY>",
"prepare": "npm run co:login"
},
"eslintConfig": {...},
"browserslist": {...},
"peerDependencies": {...},
"devDependencies": {...}
}
更新
我使用添加到我的 CodeArtificat 的链接
npm set registry <LINK_TO_CODE_ARTIFACT>
当我在本地执行发布脚本时,脚本第一次运行时出现此错误:
Unable to authenticate, need: Bearer realm="company/package", Basic realm="company/package"
该错误在随后的运行中消失。但是,当我在 Jenkins 管道上尝试相同的操作时,我不断收到此错误。不确定这意味着什么。我在 Azure 上看到了与此错误相关的线程,但在 AWS CodeArtifact 上找不到任何内容。