Это странное поведение, от которого я не могу избавиться в конвейере ADO. Когда конвейер доходит до шага npm publish, это, по-видимому, занимает много времени и в конечном итоге выходит из строя. Глядя на журналы, я вижу, что он публикует артефакт снова и снова и снова и снова увеличивает номер версии, пока не истечет время ожидания. Версия в файле package.json установлена только на 1.0.2, но артефакт в ADO — 1.0.347, и если я не обновлю версию package.json, публикация не удастся из-за несоответствия версий.
Вот пример журналов:
...
2024-05-29T20:31:20.6133756Z npm notice 📦 @comp/[email protected]
2024-05-29T20:31:20.6140379Z npm notice Tarball Contents
2024-05-29T20:31:20.6140604Z npm notice 3.0kB dist/base-theme.d.ts
2024-05-29T20:31:20.6140882Z npm notice 35.4kB dist/base-theme.js
2024-05-29T20:31:20.6141086Z npm notice 85B dist/dark/dark-theme.d.ts
2024-05-29T20:31:20.6147763Z npm notice 11.0kB dist/dark/dark-theme.js
2024-05-29T20:31:20.6148073Z npm notice 139B dist/index.d.ts
2024-05-29T20:31:20.6148210Z npm notice 139B dist/index.js
2024-05-29T20:31:20.6148572Z npm notice 87B dist/light/light-theme.d.ts
2024-05-29T20:31:20.6148781Z npm notice 7.4kB dist/light/light-theme.js
2024-05-29T20:31:20.6150824Z npm notice 1.3kB package.json
2024-05-29T20:31:20.6150962Z npm notice Tarball Details
2024-05-29T20:31:20.6151228Z npm notice name: @comp/themes
2024-05-29T20:31:20.6151371Z npm notice version: 1.0.11
2024-05-29T20:31:20.6151593Z npm notice filename: comp-themes-1.0.11.tgz
2024-05-29T20:31:20.6155236Z npm notice package size: 7.5 kB
2024-05-29T20:31:20.6155377Z npm notice unpacked size: 58.6 kB
2024-05-29T20:31:20.6155599Z npm notice shasum: 6d87331e83e4b9e38d32ca1bfb98c3d1d5f5b1e1
2024-05-29T20:31:20.6155872Z npm notice integrity: sha512-L8fkf6ZXKlfyk[...]qt62SzSvIxpuQ==
2024-05-29T20:31:20.6156099Z npm notice total files: 9
2024-05-29T20:31:20.6156216Z npm notice
2024-05-29T20:31:20.6156419Z npm notice Publishing to https://pkgs.dev.azure.com/company/_packaging/***/npm/registry/ with tag latest and default access
2024-05-29T20:31:20.6156780Z npm warn using --force Recommended protections disabled.
2024-05-29T20:31:20.6157093Z npm notice
2024-05-29T20:31:20.6160278Z npm notice 📦 @company/[email protected]
2024-05-29T20:31:20.6160442Z npm notice Tarball Contents
2024-05-29T20:31:20.6160703Z npm notice 3.0kB dist/base-theme.d.ts
2024-05-29T20:31:20.6160904Z npm notice 35.4kB dist/base-theme.js
2024-05-29T20:31:20.6161102Z npm notice 85B dist/dark/dark-theme.d.ts
2024-05-29T20:31:20.6161380Z npm notice 11.0kB dist/dark/dark-theme.js
2024-05-29T20:31:20.6161526Z npm notice 139B dist/index.d.ts
2024-05-29T20:31:20.6161721Z npm notice 139B dist/index.js
2024-05-29T20:31:20.6161920Z npm notice 87B dist/light/light-theme.d.ts
2024-05-29T20:31:20.6164140Z npm notice 7.4kB dist/light/light-theme.js
2024-05-29T20:31:20.6164307Z npm notice 1.3kB package.json
2024-05-29T20:31:20.6164439Z npm notice Tarball Details
2024-05-29T20:31:20.6164708Z npm notice name: @company/themes
2024-05-29T20:31:20.6164848Z npm notice version: 1.0.12
2024-05-29T20:31:20.6166717Z npm notice filename: company-themes-1.0.12.tgz
2024-05-29T20:31:20.6166885Z npm notice package size: 7.5 kB
2024-05-29T20:31:20.6167082Z npm notice unpacked size: 58.6 kB
2024-05-29T20:31:20.6167540Z npm notice shasum: 10bf1ac6b539617fa9a585e50b20a9335e551ca8
2024-05-29T20:31:20.6167814Z npm notice integrity: sha512-/QheV2x2X5Jvk[...]F6snh5tq52xtg==
2024-05-29T20:31:20.6171769Z npm notice total files: 9
2024-05-29T20:31:20.6171896Z npm notice
2024-05-29T20:31:20.6179565Z npm notice Publishing to https://pkgs.dev.azure.com/company/_packaging/***/npm/registry/ with tag latest and default access
2024-05-29T20:31:20.6179936Z npm warn using --force Recommended protections disabled.
2024-05-29T20:31:20.6185120Z npm notice
...
2024-05-29T20:31:21.2075844Z npm notice 📦 @company/[email protected]
2024-05-29T20:31:21.2075989Z npm notice Tarball Contents
2024-05-29T20:31:21.2076193Z npm notice 3.0kB dist/base-theme.d.ts
2024-05-29T20:31:21.2076453Z npm notice 35.4kB dist/base-theme.js
2024-05-29T20:31:21.2076670Z npm notice 85B dist/dark/dark-theme.d.ts
2024-05-29T20:31:21.2076873Z npm notice 11.0kB dist/dark/dark-theme.js
2024-05-29T20:31:21.2077031Z npm notice 139B dist/index.d.ts
2024-05-29T20:31:21.2077166Z npm notice 139B dist/index.js
2024-05-29T20:31:21.2077361Z npm notice 87B dist/light/light-theme.d.ts
2024-05-29T20:31:21.2077584Z npm notice 7.4kB dist/light/light-theme.js
2024-05-29T20:31:21.2077725Z npm notice 1.3kB package.json
2024-05-29T20:31:21.2077868Z npm notice Tarball Details
2024-05-29T20:31:21.2078061Z npm notice name: @comp/themes
2024-05-29T20:31:21.2078215Z npm notice version: 1.0.347
2024-05-29T20:31:21.2078435Z npm notice filename: comp-themes-1.0.347.tgz
2024-05-29T20:31:21.2078592Z npm notice package size: 7.5 kB
2024-05-29T20:31:21.2078742Z npm notice unpacked size: 58.6 kB
2024-05-29T20:31:21.2078902Z npm notice shasum: e2f2af4db56952b725e6e6fa882b14eadf692478
2024-05-29T20:31:21.2079171Z npm notice integrity: sha512-LCzV32TV9TiUE[...]PW/LyGkM0KYIQ==
2024-05-29T20:31:21.2079325Z npm notice total files: 9
2024-05-29T20:31:21.2079452Z npm notice
2024-05-29T20:31:21.2079787Z npm notice Publishing to https://pkgs.dev.azure.com/company/_packaging/***/npm/registry/ with tag latest and default access
2024-05-29T20:31:21.2079991Z npm error code 249
2024-05-29T20:31:21.2080141Z npm error path /home/vsts/work/1/s/src/themes
2024-05-29T20:31:21.2080277Z npm error command failed
2024-05-29T20:31:21.2080535Z npm error command sh -c tsc && npm version patch --force && npm publish
2024-05-29T20:31:21.2080882Z npm error A complete log of this run can be found in: /home/vsts/.npm/_logs/2024-05-29T20_29_46_031Z-debug-0.log
И ошибка появляется часто, пока время выполнения задания наконец не истечет.
Вот мой файл yaml для конвейера:
trigger:
branches:
include:
- master
paths:
include:
- src/themes
resources:
- repo: self
stages:
- stage: Publish
displayName: Publish Theme Package
jobs:
- job: Publish
displayName: Publish to ADO Artifact feed
pool:
vmImage: "ubuntu-latest"
steps:
- task: npmAuthenticate@0
inputs:
workingFile: "src/themes/themes.npmrc"
- task: NodeTool@0
displayName: "update node.js to latest version"
inputs:
versionSource: "spec"
versionSpec: "20.x"
checkLatest: true
- task: Npm@1
displayName: "Update npm to latest version"
inputs:
command: "custom"
customCommand: "install -g npm@latest"
- task: Npm@1
displayName: npm install
inputs:
command: install
- task: Npm@1
displayName: npm run build
inputs:
command: "custom"
customCommand: "run build"
- task: Npm@1
displayName: npm version patch
inputs:
command: "custom"
workingDir: "src/themes"
customCommand: "version patch --force"
- task: Npm@1
displayName: npm publish
inputs:
command: publish
publishRegistry: useFeed
publishFeed: "OMITTED"
workingDir: "src/themes"
Любая помощь будет оценена.
ТИА
Обновлено:
Я обновил свой файл yaml на основе некоторой информации по ссылке.
trigger:
branches:
include:
- master
paths:
include:
- src/themes
resources:
- repo: self
stages:
- stage: Publish
displayName: Publish Theme Package
jobs:
- job: Publish
displayName: Publish to ADO Artifact feed
pool:
vmImage: "ubuntu-latest"
steps:
- checkout: self
persistCredentials: true
clean: true
- task: npmAuthenticate@0
inputs:
workingFile: "src/themes/themes.npmrc"
- task: NodeTool@0
displayName: "update node.js to latest version"
inputs:
versionSource: "spec"
versionSpec: "20.x"
checkLatest: true
- task: Npm@1
displayName: "Update npm to latest version"
inputs:
command: "custom"
customCommand: "install -g npm@latest"
- task: Npm@1
displayName: npm install
inputs:
command: install
- task: Npm@1
displayName: npm run build
inputs:
command: "custom"
customCommand: "run build"
- bash: | # Grab the package version
v=`node -p "const p = require('./package.json'); p.version;"`
echo "##vso[task.setvariable variable=packageVersion]$v"
- task: CmdLine@2 # Push changes to GitHub (substitute your repo)
inputs:
script: |
git config --global user.email "[email protected]"
git config --global user.name "Azure Pipeline"
git add package.json
git commit -a -m "Automated Commit from Azure DevOps"
git push -u origin HEAD:master
- task: Npm@1
displayName: npm version patch
inputs:
command: "custom"
customCommand: "version patch -force"
- task: Npm@1
displayName: npm publish
inputs:
command: publish
publishRegistry: useFeed
publishFeed: "[REDACTED]"
workingDir: "src/themes"
Повозившись с разрешениями, мне удалось запустить его, но цикл повторился снова, и теперь у меня установлена версия 1.0.693.

Я не уверен, что заставляет конвейер увеличивать версию и публиковать снова и снова (может быть, автоматическая фиксация при запуске npm version?), но обратите внимание, что у Microsoft есть рекомендуемое решение для управления версиями пакетов npm как часть процесс сборки.
Это включает в себя отправку изменений, внесенных путем увеличения версии, обратно в ваш репозиторий (шаг, который я не вижу в вашей конфигурации, и который приведет к публикации одной и той же версии при каждом запуске конвейера).
Я бы посоветовал вам использовать упомянутое решение в качестве отправной точки и посмотреть, сохраняется ли проблема.
2024-05-29T20:31:21.2080535Z npm error command sh -c tsc && npm version patch --force && npm publish
В конце журнала мы видим фактическую команду tsc && npm version patch --force && npm publish при запуске npm publish. Это привело к тому, что команда npm publish будет запускать npm version patch, а затем npm publish снова и снова.
Вам следует удалить строку npm version patch --force && npm publish из раздела скриптов, поскольку вместо этого вы запускаете эти команды в задачах NPM.
Например, я могу воспроизвести проблему следующим образом: package.json. Версия увеличивается во много раз, пока не истечет время ожидания задания.
{
"name": "mytestpackage",
"version": "1.0.2",
"description": "a description of my test package: just for test",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"publish": "npm version patch --force && npm publish"
},
"repository": {
"type": "git",
"url": "https://[email protected]/org/project/_git/npmTest"
},
"keywords": [
"NPM",
"test"
],
"author": "My Name",
"license": "ISC"
}
Чтобы решить эту проблему, я изменил package.json и просто удалил скрипт «публиковать». Это работает.
{
"name": "mytestpackage",
"version": "1.0.206",
"description": "a description of my test package: just for test",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://[email protected]/org/project/_git/npmTest"
},
"keywords": [
"NPM",
"test"
],
"author": "My Name",
"license": "ISC"
}
Я внес некоторые изменения в файл yaml, но он все еще зацикливается.