【问题标题】:How can I ignore the actual dotenv (.env) file while running in jenkins在jenkins中运行时如何忽略实际的dotenv(.env)文件
【发布时间】:2021-03-24 20:20:30
【问题描述】:

在 cypress 中,我如何在 jenkins 中运行时忽略 dotenv (.env) 文件,因为 jenkins 在实际环境变量上运行。现在我得到No such file or directory open/student-proj/.env 如何检查它是否在 jenkins 中运行,然后使用实际的环境变量,否则使用 .env ?

plugins/index.js

const configEnv = require('dotenv').config();
const cucumber = require('cypress-cucumber-preprocessor').default;

module.exports = (on, config) => {
  on('file:preprocessor', cucumber());

  if (configEnv.error) {
    throw configEnv.error;
  }
  const env = { ...config.env, ...configEnv.parsed };
  
  const envData = { ...config, env };
  return envData;

}

【问题讨论】:

    标签: node.js jenkins jenkins-pipeline cypress cypress-cucumber-preprocessor


    【解决方案1】:

    为什么不只使用代码中特定的 jenkins env 变量,例如JOB_NAME ...如果该值返回null ...这意味着它没有在jenkins上运行

    【讨论】:

    • 如何检查 jenkins env 的值为 null ?假设 JENKINS_HOME 是 jenkins 变量之一。我可以做 `` if (JENKINS_HOME == null) { if (configEnv.error) { throw configEnv.error; } const env = { ...config.env, ...configEnv.parsed };常量 envData = { ...配置,环境 };返回环境数据; } else { // 什么都不做... }``
    • 但是上面仍然会抛出 undefined 吗?
    • 是的,JENKINS_HOME 在 Jenkins 中运行时会有一些价值,但是当你在本地机器上运行它时会为 null ......至于我没有在 cypress 上工作过的代码
    猜你喜欢
    • 2022-01-16
    • 2017-05-24
    • 2017-10-05
    • 2020-11-08
    • 2013-07-23
    • 2020-03-07
    • 2018-01-18
    • 2018-03-08
    • 2020-06-08
    相关资源
    最近更新 更多