Marcom
Marcom

Reputation: 4741

Azure pipelines working directory pointing two different places

Hi Everyone I have a question related to the pipeline.workspace variable.

In the example below i have set pipeline.workspace as the working directory and as paths for a cli command.

Npm install creates folders under /home/vsts/work/node_modules/ while the next command when i use pipeline.workspace it points to ./home/vsts/work/1/

Am I doing something wrong? or is something up?

     - task: Bash@3
          displayName: 'Publish Sentry'
          inputs:
            targetType: 'inline'
            script: |                  
              npm install @sentry/cli                                  
              .$(Pipeline.Workspace)/node_modules/.bin/sentry-cli releases --org --project new "$(Build.BuildNumber)" --finalize                      
            workingDirectory: "$(Pipeline.Workspace)"  

Upvotes: 0

Views: 882

Answers (1)

Bright Ran-MSFT
Bright Ran-MSFT

Reputation: 13744

The node_modules folder is pre-generate that may contains some global packages. It is not generated by the npm install command in the script. This situation exists on Microsoft-hosted Ubuntu agents and Microsoft-hosted macOS agents.

When executing the npm install command to install packages locally, there are few points you need to pay attention to :

  1. If no node_modules folder is existing in current working directory, and also no node_modules folder is existing in any parent directory of current working directory, the npm install command will generate the node_modules folder in current working directory and install the packages into this node_modules folder.

  2. If no node_modules folder is existing in current working directory, but the node_modules folder is existing in parent directory, the npm install command will install the packages into the existing node_modules folder in the closest parent directory.

    For example, there are the following paths:

    • /root/dir1/node_modules
    • /root/dir1/dir2/node_modules
    • /root/dir1/dir2/dir3

    When executing the npm install command in the directory "/root/dir1/dir2/dir3", the packages will be installed into "/root/dir1/dir2/node_modules".

  3. If the node_modules folder is existing in current working directory, regardless of whether the node_modules folder is existing in parent directory or not, the npm install command will install the packages into node_modules folder in current working directory.

    For example, there are the following paths:

    • /root/dir1/node_modules
    • /root/dir1/dir2/node_modules
    • /root/dir1/dir2/dir3/node_modules

    When executing the npm install command in the directory "/root/dir1/dir2/dir3", the packages will be installed into "/root/dir1/dir2/dir3/node_modules".

Upvotes: 1

Related Questions