使用 azure 工件通过 azure devops 组织共享 NPM script/app
sharing NPM script/app through azure devops organizations using azure artifacts
我有一个 git 存储库,其中包含一个 node.js“应用程序”(只有 1 个文件)及其 package.json。
我需要使用来自其他组织的 azure devops 管道的那个“应用程序”,所以我在那个 nodejs 项目中创建了一个管道,它在基于 NPM 的 azure 工件提要上对该脚本进行版本控制和发布。
在另一个组织中,在我想使用该应用程序的管道中,我使用了这样配置的“npm”任务:
steps:
- task: Npm@1
displayName: 'npm install MyPackage'
inputs:
command: custom
verbose: false
customCommand: 'install MyPackage'
customRegistry: useFeed
customFeed: '...some-guid....'
安装似乎没问题(我在第 2 个组织中创建了一个 feed,并将第 1 个组织的 feed 作为上游源,如文档中所示)。
现在,我应该如何在下一个管道任务中执行该脚本?
我尝试连接到代理,但是当我使用 运行“MyPackage”命令时,我得到“找不到命令”。
脚本安装在哪里?我应该如何执行它?
有什么东西可以放在 PATH 中吗?
我应该使用“-g”选项吗?
感谢您的帮助:)
正在更新请求的日志:
任务日志:
Starting: npm custom
==============================================================================
Task : npm
Description : Install and publish npm packages, or run an npm command. Supports npmjs.com and authenticated registries like Azure Artifacts.
Version : 1.182.0
Author : Microsoft Corporation
Help : https://docs.microsoft.com/azure/devops/pipelines/tasks/package/npm
==============================================================================
/usr/local/bin/npm --version
6.13.7
/usr/local/bin/npm config list
; cli configs
metrics-registry = "https://pkgs.dev.azure.com/org/_packaging/....some-guid..../npm/registry/"
scope = ""
user-agent = "npm/6.13.7 node/v13.11.0 darwin x64"
; environment configs
userconfig = "/Users/.../AGENTS/vsts-agent-osx-x64-2.179.0-AZURE-01/_work/10/npm/33366.npmrc"
; userconfig /Users/.../AGENTS/vsts-agent-osx-x64-2.179.0-AZURE-01/_work/10/npm/33366.npmrc
registry = "https://pkgs.dev.azure.com/org/_packaging/....some-guid..../npm/registry/"
; builtin config undefined
prefix = "/usr/local"
; node bin location = /usr/local/Cellar/node/13.11.0/bin/node
; cwd = /Users/.../AGENTS/vsts-agent-osx-x64-2.179.0-AZURE-01/_work/10/s
; HOME = /Users/...
; "npm config ls -l" to show all defaults.
/usr/local/bin/npm install -g MyPackage
+ MyPackage@1.0.20210216-1
added 198 packages from 99 contributors in 18.319s
Finishing: npm custom
这是第二个定义:
steps:
- script: |
echo "1"
node MyPackage
echo "2"
MyPackage
displayName: 'Command Line Script'
以及关联的执行日志:
Starting: Command Line Script
==============================================================================
Task : Command line
Description : Run a command line script using Bash on Linux and macOS and cmd.exe on Windows
Version : 2.182.0
Author : Microsoft Corporation
Help : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/command-line
==============================================================================
Generating script.
========================== Starting Command Output ===========================
/bin/bash --noprofile --norc /Users/.../AGENTS/vsts-agent-osx-x64-2.179.0-AZURE-01/_work/_temp/7fe7833a-ce7d-48af-ab8f-1fcf2e740c36.sh
1
internal/modules/cjs/loader.js:979
throw err;
^
Error: Cannot find module '/Users/.../AGENTS/vsts-agent-osx-x64-2.179.0-AZURE-01/_work/10/s/MyPackage'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:976:15)
at Function.Module._load (internal/modules/cjs/loader.js:859:27)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at internal/main/run_main_module.js:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
2
/Users/.../AGENTS/vsts-agent-osx-x64-2.179.0-AZURE-01/_work/_temp/7fe7833a-ce7d-48af-ab8f-1fcf2e740c36.sh: line 5: MyPackage: command not found
##[error]Bash exited with code '127'.
Finishing: Command Line Script
比如你在第一个组织中创建了一个feed,并在feed中添加了npm包,现在你想在第二个组织中使用这个包,我们需要在第二个组织的feed中设置upstream source,例如azure-feed://myOrg/myProject/myFeed@local
,那么我们可以在第二个组织管道中安装和使用该包。
您还可以查看此 blog 了解更多详情。
更新1
I need to find the path where it is installed
我们可以添加任务 Command line
和 运行 npm list
来查看当前位置已安装的非全局库。查看此 ticket and blog 了解更多详情。
安装路径为$(Build.SourcesDirectory)/node_modules
,我们可以添加任务bash和运行 ls '$(Build.SourcesDirectory)/node_modules'
查看。
终于找到问题了:
- 1st 我必须使用
-g
选项全局安装包
- 第二次我不得不使用
npx
来
运行它。
- 3rd 我不得不更新
package.json
为:
"bin": {
"NAME_OF_THE_BINARY": "./FILE_TO_EXECUTE.js"
},
我有一个 git 存储库,其中包含一个 node.js“应用程序”(只有 1 个文件)及其 package.json。
我需要使用来自其他组织的 azure devops 管道的那个“应用程序”,所以我在那个 nodejs 项目中创建了一个管道,它在基于 NPM 的 azure 工件提要上对该脚本进行版本控制和发布。
在另一个组织中,在我想使用该应用程序的管道中,我使用了这样配置的“npm”任务:
steps:
- task: Npm@1
displayName: 'npm install MyPackage'
inputs:
command: custom
verbose: false
customCommand: 'install MyPackage'
customRegistry: useFeed
customFeed: '...some-guid....'
安装似乎没问题(我在第 2 个组织中创建了一个 feed,并将第 1 个组织的 feed 作为上游源,如文档中所示)。
现在,我应该如何在下一个管道任务中执行该脚本? 我尝试连接到代理,但是当我使用 运行“MyPackage”命令时,我得到“找不到命令”。 脚本安装在哪里?我应该如何执行它? 有什么东西可以放在 PATH 中吗? 我应该使用“-g”选项吗?
感谢您的帮助:)
正在更新请求的日志:
任务日志:
Starting: npm custom
==============================================================================
Task : npm
Description : Install and publish npm packages, or run an npm command. Supports npmjs.com and authenticated registries like Azure Artifacts.
Version : 1.182.0
Author : Microsoft Corporation
Help : https://docs.microsoft.com/azure/devops/pipelines/tasks/package/npm
==============================================================================
/usr/local/bin/npm --version
6.13.7
/usr/local/bin/npm config list
; cli configs
metrics-registry = "https://pkgs.dev.azure.com/org/_packaging/....some-guid..../npm/registry/"
scope = ""
user-agent = "npm/6.13.7 node/v13.11.0 darwin x64"
; environment configs
userconfig = "/Users/.../AGENTS/vsts-agent-osx-x64-2.179.0-AZURE-01/_work/10/npm/33366.npmrc"
; userconfig /Users/.../AGENTS/vsts-agent-osx-x64-2.179.0-AZURE-01/_work/10/npm/33366.npmrc
registry = "https://pkgs.dev.azure.com/org/_packaging/....some-guid..../npm/registry/"
; builtin config undefined
prefix = "/usr/local"
; node bin location = /usr/local/Cellar/node/13.11.0/bin/node
; cwd = /Users/.../AGENTS/vsts-agent-osx-x64-2.179.0-AZURE-01/_work/10/s
; HOME = /Users/...
; "npm config ls -l" to show all defaults.
/usr/local/bin/npm install -g MyPackage
+ MyPackage@1.0.20210216-1
added 198 packages from 99 contributors in 18.319s
Finishing: npm custom
这是第二个定义:
steps:
- script: |
echo "1"
node MyPackage
echo "2"
MyPackage
displayName: 'Command Line Script'
以及关联的执行日志:
Starting: Command Line Script
==============================================================================
Task : Command line
Description : Run a command line script using Bash on Linux and macOS and cmd.exe on Windows
Version : 2.182.0
Author : Microsoft Corporation
Help : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/command-line
==============================================================================
Generating script.
========================== Starting Command Output ===========================
/bin/bash --noprofile --norc /Users/.../AGENTS/vsts-agent-osx-x64-2.179.0-AZURE-01/_work/_temp/7fe7833a-ce7d-48af-ab8f-1fcf2e740c36.sh
1
internal/modules/cjs/loader.js:979
throw err;
^
Error: Cannot find module '/Users/.../AGENTS/vsts-agent-osx-x64-2.179.0-AZURE-01/_work/10/s/MyPackage'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:976:15)
at Function.Module._load (internal/modules/cjs/loader.js:859:27)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at internal/main/run_main_module.js:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
2
/Users/.../AGENTS/vsts-agent-osx-x64-2.179.0-AZURE-01/_work/_temp/7fe7833a-ce7d-48af-ab8f-1fcf2e740c36.sh: line 5: MyPackage: command not found
##[error]Bash exited with code '127'.
Finishing: Command Line Script
比如你在第一个组织中创建了一个feed,并在feed中添加了npm包,现在你想在第二个组织中使用这个包,我们需要在第二个组织的feed中设置upstream source,例如azure-feed://myOrg/myProject/myFeed@local
,那么我们可以在第二个组织管道中安装和使用该包。
您还可以查看此 blog 了解更多详情。
更新1
I need to find the path where it is installed
我们可以添加任务 Command line
和 运行 npm list
来查看当前位置已安装的非全局库。查看此 ticket and blog 了解更多详情。
安装路径为$(Build.SourcesDirectory)/node_modules
,我们可以添加任务bash和运行 ls '$(Build.SourcesDirectory)/node_modules'
查看。
终于找到问题了:
- 1st 我必须使用
-g
选项全局安装包 - 第二次我不得不使用
npx
来 运行它。 - 3rd 我不得不更新
package.json
为:
"bin": {
"NAME_OF_THE_BINARY": "./FILE_TO_EXECUTE.js"
},