当我尝试将我的 cypress 测试(通过 nodejs 和 .yml)包含到 azure DevOps 中时,出现以下错误:
Npm failed with return code: 254
这是什么意思,我该如何解决?
我的完整日志在这里:
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
我使用以下 YAML: 为了创建这个 yaml,我使用了将 Cypress 持续集成到 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'
最佳答案
根据您在日志中的错误消息:ENOENT: no such file or directory, open ‘/home/vsts/work/package.json’
,npm 找不到您的 package.json 文件。请检查您的 package.json 在哪个文件夹中。例如:
我的 package.json 在 web/app 文件夹中。我需要在 npm 任务中将此文件夹设置为工作文件夹。
这是我的 npm 任务的配置:
- task: Npm@1
inputs:
command: 'custom'
workingDir: '$(Build.SourcesDirectory)/web/app'
customCommand: 'run test'
continueOnError: true
关于npm - 如何解决 npm 错误代码 : 254 in azure DevOps?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63808454/