2

I have a git repository containing a node.js "app" (only 1 file) with its package.json.

I need to use that "app" from azure devops pipeline of other organizations, so I made a pipeline in that nodejs project that makes a versioning+publish of that script on a NPM based azure artifact feed.

On another organization, in the pipeline where I wanted to use that app, I used an "npm" task configured like that :

steps:
- task: Npm@1
  displayName: 'npm install MyPackage'
  inputs:
    command: custom
    verbose: false
    customCommand: 'install MyPackage'
    customRegistry: useFeed
    customFeed: '...some-guid....'

The installs seems ok (I created a feed in the 2nd organization with the feed of 1st organization as upstream source as indicated in the doc).

Now, how am I supposed to exec that script in the next pipeline task ? I tried to connect to the agent, but when I run "MyPackage" command, I get "command not found". Where is the script installed ? How am I supposed to execute it ? Is there something to put in the PATH ? Should I use the "-g" option ?

Thanks for your help :)

Updating with the requested logs :

Task log :

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://learn.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

Here is the 2nd definition :

steps:
- script: |
   echo "1"
   node MyPackage
   
   echo "2"
   MyPackage
   
  displayName: 'Command Line Script'

And the associated execution log :

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://learn.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

LiohAu
  • 611
  • 12
  • 36

2 Answers2

0

We could add an Azure Artifacts feed in a different organization within your Azure AD tenant as an upstream source.

For example, you create a feed in the first organization, and add npm package to the feed, now you want to use the package in the second organization, we need to set the upstream source in the second organization feed, such as azure-feed://myOrg/myProject/myFeed@local, then we could install and use the package in the second organization pipeline.

You could also check this blog for more details.

Update1

I need to find the path where it is installed

We could add task Command line and run npm list to see the installed non-global libraries for your current location. Check this ticket and blog for more details.

The install path is $(Build.SourcesDirectory)/node_modules, we could add task bash and run ls '$(Build.SourcesDirectory)/node_modules' to check it.

Vito Liu
  • 7,525
  • 1
  • 8
  • 17
  • `when I run "MyPackage" command, I get "command not found"` could you share the detail log and the task definition here? You could also check this [ticket](https://stackoverflow.com/questions/31472755/sudo-npm-command-not-found) for troubleshooting – Vito Liu Feb 16 '21 at 03:30
  • I already shared the task definition for the NPM install part. The install of my executable/package seems ok, even across organization, this is not my asking since that part works. The issue is to run the "package". I don't know where it is installed. I thnk one part of the solution is to add " #!/usr/bin/env node" at the top of my .js file to be able to execute without "node" in front of it. But still I need to find the path where it is installed... – LiohAu Feb 16 '21 at 08:24
  • Hi @LiohAu, I have updated the answer, check the update1, we could run the cmd npm list to see the install path. – Vito Liu Feb 17 '21 at 07:24
0

Finally found the issues :

  • 1st I had to install the package globally with the -g option
  • 2nd I had to use npx to run it.
  • 3rd I had to update the package.json with :
  "bin": {
    "NAME_OF_THE_BINARY": "./FILE_TO_EXECUTE.js"
  },
LiohAu
  • 611
  • 12
  • 36