When I try to include my cypress tests (via nodejs & .yml) to azure DevOps, I get the following Error:
Npm failed with return code: 254
What does it mean and how can I solve this?
My complete Log is here:
Starting: Npm
==============================================================================
Task : npm
Description : Install and publish npm packages, or run an npm command. Supports npmjs.com and authenticated registries like Azure Artifacts.
Version : 1.174.0
Author : Microsoft Corporation
Help : https://learn.microsoft.com/azure/devops/pipelines/tasks/package/npm
==============================================================================
SYSTEMVSSCONNECTION exists true
SYSTEMVSSCONNECTION exists true
/opt/hostedtoolcache/node/10.22.0/x64/bin/npm --version
6.14.6
/opt/hostedtoolcache/node/10.22.0/x64/bin/npm config list
; cli configs
metrics-registry = "https://registry.npmjs.org/"
scope = ""
user-agent = "npm/6.14.6 node/v10.22.0 linux x64"
; environment configs
userconfig = "/home/vsts/work/1/npm/2560.npmrc"
; node bin location = /opt/hostedtoolcache/node/10.22.0/x64/bin/node
; cwd = /home/vsts/work/1/s
; HOME = /home/vsts
; "npm config ls -l" to show all defaults.
/opt/hostedtoolcache/node/10.22.0/x64/bin/npm run test
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /home/vsts/work/package.json
npm ERR! errno -2
I use the following YAML:
To create this yaml i used a tutorial for Continuous integration of Cypress into azure devops.
# Node.js
# Build a general Node.js project with npm.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://learn.microsoft.com/azure/devops/pipelines/languages/javascript
trigger:
- master
pool:
vmImage: 'ubuntu-latest'
steps:
- task: NodeTool#0
inputs:
versionSpec: '10.x'
displayName: 'Install Node.js'
- script: |
npm install
displayName: 'npm install'
- task: Npm#1
inputs:
command: 'custom'
customCommand: 'run test'
continueOnError: true
- task: PublishTestResults#2
inputs:
testResultsFormat: 'JUnit'
testResultsFiles: '*.xml'
searchFolder: '$(System.DefaultWorkingDirectory)/cypress/reports/junit'
mergeTestResults: true
testRunTitle: 'Publish Test Results'
According to your error message in your logs:ENOENT: no such file or directory, open ‘/home/vsts/work/package.json’, npm cannot find your package.json file. Please check which folder your package.json is in. For example:
My package.json is in the web/app folder. I need to set this folder as working folder in npm task.
Here is the configuration of my npm task:
- task: Npm#1
inputs:
command: 'custom'
workingDir: '$(Build.SourcesDirectory)/web/app'
customCommand: 'run test'
continueOnError: true
Related
I've created a public npm repository: https://www.npmjs.com/package/point-cloud-visualiser
I'm trying to run npm publish from within codebuild. I have generated a token and saved it in AWS secrets manager. I am succesfully pulling the secret in the buildspec. However I am unsure how to configure the .npmrc file so that it uses the token and doesn't tell me to login.
Currently my .npmrc looks like this:
#point-cloud-visualiser:registry=https://www.npmjs.com/package/point-cloud-visualiser
//point-cloud-visualiser/:_authToken=${NPM_TOKEN}
And my buildspec.yml looks like this:
version: 0.2
env:
secrets-manager:
NPM_TOKEN: "npm-token:npm-token"
phases:
install:
commands:
- npm install
build:
commands:
- npm run build
- npm publish
But when it fails on npm publish giving the error:
npm ERR! code ENEEDAUTH
npm ERR! need auth This command requires you to be logged in to https://registry.npmjs.org/
npm ERR! need auth You need to authorize this machine using `npm adduser`
I have also tried removing the .npmrc file and using the following in the buildspec.yml:
version: 0.2
env:
secrets-manager:
NPM_TOKEN: "npm-token:npm-token"
phases:
install:
commands:
- npm install
build:
commands:
- npm run build
- npm config set registry 'https://www.npmjs.com/package/point-cloud-visualiser'
- npm config set '//npmjs.com/package/point-cloud-visualiser/:always-auth' 'true'
- npm config set '//npmjs.com/package/point-cloud-visualiser/:_authToken' '${NPM_TOKEN}'
- npm publish
But this approach gives the same result as above. What am I doing wrong? Thank you!
The following buildspec worked succesfully:
version: 0.2
env:
secrets-manager:
NPM_TOKEN: "npm-token:npm-token"
phases:
install:
commands:
- npm install
build:
commands:
- npm run build
- echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/.npmrc
- echo "//registry.npmjs.org/:always-auth=true" >> ~/.npmrc
- npm publish
I hae a problem running npm version patch on Azure Pipelines. Initially, I discovered that SonarCloud scanner drops unwanted files in the repository. I git-ignored the directory
Consider the following fragment
- script: git checkout -f $(Build.SourceBranchName)
displayName: Force checkout of current branch
- script: git status
displayName: Git status
- script: git reset --hard
displayName: Git reset
- task: Npm#1
displayName: Tag repository and set release version
inputs:
command: custom
customCommand: version patch
- script: git push origin $(Build.SourceBranchName) --tags
displayName: Git push with tags
Required in order to push a subsequent commit
Displays a summary of the repository
Unhappy with git-status ok, I force cleaning the repo
Makes a commit and a tag out of the repository
Pushes branch and tag
git-status output
Starting: Git status
==============================================================================
Task : Command line
Description : Run a command line script using Bash on Linux and macOS and cmd.exe on Windows
Version : 2.201.1
Author : Microsoft Corporation
Help : https://learn.microsoft.com/azure/devops/pipelines/tasks/utility/command-line
==============================================================================
Generating script.
Script contents:
git status
========================== Starting Command Output ===========================
/usr/bin/bash --noprofile --norc /home/vsts/work/_temp/447a869a-56d7-4a29-a4c0-9a49b5ffce74.sh
On branch main
Your branch is up to date with 'origin/main'.
nothing to commit, working tree clean
Finishing: Git status
git-reset output
Starting: Git reset
==============================================================================
Task : Command line
Description : Run a command line script using Bash on Linux and macOS and cmd.exe on Windows
Version : 2.201.1
Author : Microsoft Corporation
Help : https://learn.microsoft.com/azure/devops/pipelines/tasks/utility/command-line
==============================================================================
Generating script.
Script contents:
git reset --hard
========================== Starting Command Output ===========================
/usr/bin/bash --noprofile --norc /home/vsts/work/_temp/85fedcd4-9756-4d38-aa3d-d41c03032565.sh
HEAD is now at ad6aebf Pipelines
Finishing: Git reset
npm-version output
Starting: Tag repository and set release version
==============================================================================
Task : npm
Description : Install and publish npm packages, or run an npm command. Supports npmjs.com and authenticated registries like Azure Artifacts.
Version : 1.202.0
Author : Microsoft Corporation
Help : https://learn.microsoft.com/azure/devops/pipelines/tasks/package/npm
==============================================================================
/opt/hostedtoolcache/node/16.15.0/x64/bin/npm --version
8.5.5
/opt/hostedtoolcache/node/16.15.0/x64/bin/npm config list
; "project" config from /home/vsts/work/1/s/.npmrc
message = ":[npm-autoversion]: %s"
; "env" config from environment
cache = "/home/vsts/work/1/.npm"
userconfig = "/home/vsts/work/1/npm/7212.npmrc"
; node bin location = /opt/hostedtoolcache/node/16.15.0/x64/bin/node
; cwd = /home/vsts/work/1/s
; HOME = /home/vsts
; Run `npm config ls -l` to show all defaults.
/opt/hostedtoolcache/node/16.15.0/x64/bin/npm version patch
npm ERR! Git working directory not clean.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/vsts/work/1/.npm/_logs/2022-05-19T13_01_16_005Z-debug-0.log
##[warning]Couldn't find a debug log in the cache or working directory
##[error]Error: Npm failed with return code: 1
Finishing: Tag repository and set release version
Question: how is it possible that npm fails to make a version bump if I am triple-sure that the repository is clean?
I'm currently having an issue with my CI Pipeline since it doesn't let me install my private npm dependency.
I'm currently able to push that image to the NPM Registry, but I can't use it in a different project. My pipeline look like this:
trigger:
batch: true
branches:
include:
- main
paths:
exclude:
- README.md
pool:
vmImage: "ubuntu-latest"
parameters:
- name: npm_token_private
displayName: Private Secret
type: string
default: my_secrets
values:
- my_secrets
- name: container_registry
displayName: ContainerRegistry
type: string
default: test01
values:
- test01
- test02
variables:
- group: ${{ parameters.npm_token_private }}
- name: repository
value: QA-Test
- name: containerRegistry
value: ${{parameters.container_registry}}
- name: Tags
value: master
stages:
- stage: Getting_Access_Repo
displayName: Preparing app for deployment
jobs:
- job:
continueOnError: false
steps:
# Gives access to repo
- checkout: self
clean: true
persistCredentials: true
- task: UseNode#1
inputs:
version: '14.x'
- script: npm set //registry.npmjs.org/:_authToken $(npm_token_private)
displayName: "Set Private Registry"
- script: npm i #test/logger
displayName: Installing logger
My issue is the following:
npm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmjs.org/#test%2flogger - Not found
npm ERR! 404
npm ERR! 404 '#test/logger#^1.0.14' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/vsts/.npm/_logs/2022-03-14T19_39_45_779Z-debug.log
##[error]Bash exited with code '1'.
What I don't understand is that I can push a new image to the NPM Registry by using the same npm_token_ptivate. Does someone knows if I have to recreate a new token or what else do I have to do?
I am trying to dynamically update a package.json as part of a CI build for publishing to an npm repository.
I am following a simple scheme of yyyymm.dd.rev to create the version number.
I have followed npm version in Azure Dev Ops pipeline.
My powershell script to update variables:
variables:
major: 1
minor: 0
patch: 0
rev: 0
packageVersion: '$(major)$(minor).$(patch).$(rev)'
steps:
- task: PowerShell#2
displayName: Set SemVer values
inputs:
targetType: 'inline'
script: |
$year = Get-Date -Format "yyyy"
$month = Get-Date -Format "MM"
$day = Get-Date -Format "dd"
$rev = Get-Date -Format "HHmm"
Write-Host "##vso[task.setvariable variable=major]$year"
Write-Host "##vso[task.setvariable variable=minor]$month"
Write-Host "##vso[task.setvariable variable=patch]$day"
Write-Host "##vso[task.setvariable variable=rev]$rev"
With the variable set - I am calling the npm version command to update the package.json
- task: Npm#1
displayName: Update Version of my package
inputs:
command: 'custom'
workingDir: 'libs/my-package'
customCommand: 'version $(packageVersion) --no-git-tag-version --loglevel verbose'
I keep getting an npm failure. This runs fine if I execute it locally - just on the build server do I see failure:
/usr/local/bin/npm --version
6.14.15
/usr/local/bin/npm config list
; cli configs
metrics-registry = "https://registry.npmjs.org/"
scope = ""
user-agent = "npm/6.14.15 node/v14.18.1 linux x64"
; environment configs
userconfig = "/home/vsts/work/1/npm/17197.npmrc"
; node bin location = /usr/local/bin/node
; cwd = /home/vsts/work/1/s/libs/my-library
; HOME = /home/vsts
; "npm config ls -l" to show all defaults.
**/usr/local/bin/npm version 202111.04.1901 --no-git-tag-version --loglevel verbose**
npm info it worked if it ends with ok
npm verb cli [
npm verb cli '/usr/local/bin/node',
npm verb cli '/usr/local/bin/npm',
npm verb cli 'version',
npm verb cli '202111.04.1901',
npm verb cli '--no-git-tag-version',
npm verb cli '--loglevel',
npm verb cli 'verbose'
npm verb cli ]
npm info using npm#6.14.15
npm info using node#v14.18.1
npm ERR! npm version [<newversion> | major | minor | patch | premajor | preminor | prepatch | prerelease [--preid=<prerelease-id>] | from-git]
npm ERR! (run in package dir)
npm ERR! 'npm -v' or 'npm --version' to print npm version (6.14.15)
npm ERR! 'npm view <pkg> version' to view a package's published version
npm ERR! 'npm ls' to inspect current package/dependency versions
npm verb exit [ 1, true ]
npm timing npm Completed in 117ms
npm verb code 1
##[warning]Couldn't find a debug log in the cache or working directory
##[error]Error: Npm failed with return code: 1
Finishing: Update Version of my package
I eventually did find an answer to this problem. Azure DevOps allows for Running git commands in a pipeline.
So the solution is twofold:
You need to provide your build permission to access your repository
In the pipeline I added these steps
steps:
- checkout: self
persistCredentials: true
clean: true
- task: Powershell#2
displayName: Checkout Branch and Initialize Defaults
inputs:
targetType: inline
script: |
$branch = "$(Build.SourceBranch)" -replace "refs/heads/"
git checkout $branch
git config --global user.email "ci#somorg.com"
git config --global user.name "Azure CI Build"
- task: Bash#3
displayName: Update the package version
condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest'))
inputs:
workingDirectory: $(projectDirectory)
targetType: inline
script: |
npm version patch -m "update version to %s [skip ci]" --force
- task: Bash#3
displayName: Push Changes
condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest'))
inputs:
targetType: inline
script: |
git add .
git commit -m "CI: update version [skip ci]"
git push
I'm learning how to use YAML files in my build pipeline and I need to change eslint settings. Specifically, I'm trying to disable the rule that checks for console statements. I've modified it in my local .eslintrc.js file, but the pipeline doesn't appear to use the settings in that file. Am I going about this the right way?
Here's what I have so far:
trigger:
- master
pool:
vmImage: 'ubuntu-latest'
steps:
- task: NodeTool#0
inputs:
versionSpec: '10.x'
displayName: 'Install Node.js'
- script: |
npm install
npm run build
displayName: 'npm install and build'
You have not added any command to run the linter.
Add an additional command like so in the yaml.
- script: |
npm install
eslint src
npm run build
displayName: 'npm install, lint and build'
Or for better clarity, you can add a custom script in the package.json file, as below
"scripts": {
...
"linter": "eslint src",
...
}
then call it from the yaml.
- script: |
npm install
npm run linter
npm run build
displayName: 'npm install, lint and build'