skip to Main Content

This is strange behavior that I can’t seem to get rid of in the ADO pipeline. When the pipeline gets to the npm publish step it seemingly takes a long time and eventually fails. Looking at the logs, I can see that it is publishing the artifact over and over and incrementing the version number over and over again until the timeout is reached. The version in the package.json file is only set to 1.0.2, but the artifact in ADO is 1.0.347, and unless I update the version package.json, the publish fails because of the version mismatch.

Here is a sample of the logs:

...
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

And the error shows up a lot until the job finally times out.

Here is my yaml file for the pipeline:

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"

Any help would be apprciated.

TIA

EDIT:

I’ve updated my yaml file based on some of the information in the link.

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"

After messing around with permissions, I got it to run, but the looping happened again, and now I’m up to version 1.0.693.

2

Answers


  1. I’m not sure what causes the the pipeline to increment the version and publish over and over again (maybe the automatic commit by running npm version?), but please note that Microsoft has a recommended solution for versioning npm packages as part of the build process.

    This includes pushing the changes made by incrementing the version back to your repo (a step I do not see in your configuration, and which would lead to publishing the same version in every pipeline run).

    I would advise you to use the mentioned solution as a starting point, and see if the issue persists.

    Login or Signup to reply.
  2. 2024-05-29T20:31:21.2080535Z npm error command sh -c tsc && npm version patch --force && npm publish
    

    At the end of the log, we can see the actual command is tsc && npm version patch --force && npm publish when you run npm publish. This caused the npm publish command will run the npm version patch and then npm publish again and again.

    You should remove the npm version patch --force && npm publish line from the scripts section as you are running these commands in the NPM tasks instead.

    For example, I can reproduce the issue with the following package.json. The version is increased many times until the job time out.

    {
      "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"
    }
    
    

    To solve the issue, I changed the package.json and just deleted the "publish" script. This works.

    {
      "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"
    }
    
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search