我对这个gitlab世界是新来的。
我有一个私人项目。我可以使用命令提示符发布包。
我的.npmrc文件
@ui-practice:registry=https://gitlab.MyCompany.com/api/v4/packages/npm/
//gitlab.MyCompany.com/api/v4/packages/npm/:_authToken=PrivateToken
//gitlab.MyCompany.com/api/v4/projects/MyProjectID/packages/npm/:_authToken=PrivateToken
但我无法使用Gitlab CICD发布,它给出了以下错误
npm ERR! need auth This command requires you to be logged in to https://gitlab.MyCompany.com/api/v4/projects/MyProjectID/packages/npm/
npm ERR! need auth You need to authorize this machine using `npm adduser`
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Windows\system32\config\systemprofile\AppData\Local\npm-cache\_logs\2022
我的.gitlab-ci.yml
image: node:latest
stages:
- deploy
deploy:
stage: deploy
script:
- echo "@MyScope:registry=https://${CI_SERVER_HOST}/api/v4/packages/npm/">.npmrc
- echo "//${CI_SERVER_HOST}/api/v4/packages/npm/:_authToken=${CI_JOB_TOKEN}">>.npmrc
- echo "//${CI_SERVER_HOST}/api/v4/projects/${CI_PROJECT_ID}/packages/npm/:_authToken=${CI_JOB_TOKEN}">>.npmrc
- echo "Created the following .npmrc:"; cat .npmrc
- npm publish
CI_JOB_TOKEN-我已经创建了部署令牌并添加到gitlab变量中
我的软件包. json
{
"name": "@MyScope/MyPackageName",
"version": "1.0.23",
"description": "My Library.",
"publishConfig": {
"@MyScope:registry": "https://gitlab.MyCompany.com/api/v4/projects/MyProjectID/packages/npm/"
},
"scripts": {
"test": "web-test-runner \"./stories/**/*.test.js\" --node-resolve",
"storybook": "start-storybook -p 6006",
"build-storybook": "build-storybook",
"chromatic": "npx chromatic --project-token=78290d9f7c4f",
"build": "rimraf build && rollup -c",
"prepublishOnly": "npm install && npm run build",
"pack:dev": "npm pack && move *.tgz node_modules_offline/"
},
"repository": {
"type": "git",
"url": "https://gitlab.MyCompany.com/MyScope/MyPackageName.git"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@applitools/eyes-storybook": "^3.27.6",
"@babel/core": "^7.17.7",
"@babel/plugin-proposal-class-properties": "^7.16.7",
"@babel/plugin-proposal-decorators": "^7.17.2",
"@babel/plugin-proposal-export-default-from": "^7.16.7",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.7",
"@babel/plugin-proposal-object-rest-spread": "^7.17.3",
"@babel/plugin-proposal-optional-chaining": "^7.16.7",
"@babel/plugin-proposal-private-methods": "^7.16.11",
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
"@babel/plugin-transform-arrow-functions": "^7.16.7",
"@babel/plugin-transform-block-scoping": "^7.16.7",
"@babel/plugin-transform-classes": "^7.16.7",
"@babel/plugin-transform-destructuring": "^7.17.7",
"@babel/plugin-transform-for-of": "^7.16.7",
"@babel/plugin-transform-parameters": "^7.16.7",
"@babel/plugin-transform-runtime": "^7.17.0",
"@babel/plugin-transform-shorthand-properties": "^7.16.7",
"@babel/plugin-transform-spread": "^7.16.7",
"@babel/preset-env": "^7.16.11",
"@babel/preset-typescript": "^7.16.7",
"@rollup/plugin-babel": "^5.3.1",
"@rollup/plugin-commonjs": "^21.1.0",
"@rollup/plugin-node-resolve": "^13.2.1",
"@rollup/plugin-strip": "^2.1.0",
"@rollup/plugin-typescript": "^8.3.2",
"@storybook/addon-a11y": "^6.4.19",
"@storybook/addon-actions": "^6.4.19",
"@storybook/addon-essentials": "^6.4.19",
"@storybook/addon-links": "^6.4.19",
"@storybook/addons": "^6.4.19",
"@storybook/preset-scss": "^1.0.3",
"@storybook/theming": "^6.4.19",
"@storybook/web-components": "^6.4.19",
"babel-loader": "^8.2.3",
"babel-plugin-macros": "^3.1.0",
"babel-plugin-polyfill-corejs3": "^0.5.2",
"chromatic": "^6.5.4",
"core-js": "^3.21.1",
"css-loader": "^5.2.7",
"eslint": "^8.11.0",
"html-minifier-terser": "^7.0.0-alpha.2",
"rimraf": "^3.0.2",
"rollup": "^2.70.2",
"rollup-plugin-copy": "^3.4.0",
"rollup-plugin-dts": "^4.2.1",
"rollup-plugin-minify-html-literals": "^1.2.6",
"rollup-plugin-peer-deps-external": "^2.2.4",
"rollup-plugin-scss": "^3.0.0",
"rollup-plugin-terser": "^7.0.2",
"sass": "^1.49.9",
"sass-loader": "^10.2.1",
"storybook-dark-mode": "^1.0.9",
"style-loader": "^2.0.0"
},
"dependencies": {
"@esm-bundle/chai": "^4.3.4-fix.0",
"i18next": "^21.6.14",
"lit-html": "^2.2.0",
"node-sass": "^6.0.1"
},
"main": "build/cjs/index",
"module": "build/esm/index",
"files": [
"build"
]
}
缺少什么?知道为什么gitlab要求我再次登录吗?
need auth此命令要求您登录到
它能够构建工件,只是在使用CICD发布包时出现了问题,从Visual Studio终端来看,它工作正常。
4条答案
按热度按时间nfzehxib1#
我遇到了同样的问题,它对我们两个都不起作用的原因与我们使用的注册表端点有关。我们两个都使用示例级端点,不能用于发布任何内容。
这是您的.npmrc,其中包含(像我的一样)示例级注册表
这是您从.gitlab-ci.yml中提取的内容
我的解决方案是将第一个echo更改为:
这将从示例级包切换到项目级包,在项目级包中您可以实际发布包。
4si2a6ki2#
将
echo "Created the following .npmrc:"; cat .npmrc
的输出与您的本地.npmrc
文件进行比较。是否存在任何差异?是否可能CI中的一个或多个环境变量为空?ee7vknir3#
感谢您的回复,两者相同
我的本地.npmrc文件
并从.yml文件(即cat .npmrc)输出
已创建以下.npmrc:
fsi0uk1n4#
我有同样的问题,我可以修复它与正确的网址在package.json。希望这有帮助。