如何修复“错误:ENOENT:没有这样的文件或目录 - jenkins 中的 cypress 插件”

问题描述 投票:0回答:2

赛普拉斯测试 --> 我将以下代码添加到 plugins/index.js ,本地测试运行良好,但在 jenkins 上运行时出现错误

function getConfigurationByFile(file) {
  const pathToConfigFile = path.resolve(
    '..',
    'automation/cypress/configFiles',
    `${file}.json`
  );

  return fs.readJson(pathToConfigFile);
}

module.exports = (on, config) => {
  const file = config.env.fileConfig || 'qat';

  return getConfigurationByFile(file);
};

詹金斯错误 -->

插件文件导出的函数抛出错误。 我们调用了

/var/lib/jenkins/jenkins-agent/workspace/ui-automation/cypress/plugins/index.js
导出的函数,但它抛出了错误。

错误:ENOENT:没有这样的文件或目录,打开 '/var/lib/jenkins/jenkins-agent/workspace/automation/cypress/configFiles/qat.json'

javascript jenkins testing automated-tests cypress
2个回答
0
投票

我能够解决这个问题。我的代码中的工作空间路径不正确。

jenkins 工作区:工作区/ui-automation/cypress/

本地工作区:工作区/自动化/cypress

更新代码:

  const pathToConfigFile = path.resolve(
    '..',
    'ui-automation/cypress/configFiles',
    `${file}.json`
  );

  return fs.readJson(pathToConfigFile);
}

module.exports = (on, config) => {
  const file = config.env.fileConfig || 'qat';

  return getConfigurationByFile(file);
};

0
投票

我在本地遇到了同样的错误。 强制安装后解决。安装 cypress 时尝试使用 --force 标志

npm install cypress --force
© www.soinside.com 2019 - 2024. All rights reserved.