OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Github actions CI/CD pipeline is unable to retrieve environment variables from cypress.config.ts

  • Thread starter Thread starter Shivam Srivastava
  • Start date Start date
S

Shivam Srivastava

Guest
In my GitHub Actions CI/CD pipeline, there is a step for Cypress end-to-end tests that uses the command npx nx run ${{ inputs.repo_project_name }}:e2e.

My end-to-end tests are failing because they are unable to retrieve environment variables. The end-to-end tests run successfully locally but fail to execute in the CI/CD GitHub Actions environment.

Here is my Cypress configuration file:

Code:
import { defineConfig } from 'cypress';
import { nxE2EPreset } from '@nx/cypress/plugins/cypress-preset';
import { nxComponentTestingPreset } from '@nx/next/plugins/component-testing';

export default defineConfig({
  component: {
    ...nxComponentTestingPreset(__filename),
  },
  e2e: {
    ...nxE2EPreset(__filename, { cypressDir: 'cypress' }),
    baseUrl: 'http://localhost:4201',
    pageLoadTimeout: 100000,
    env: {
      JDC_ALIAS: 'http://localhost:4201',
      CYPRESS_UAM_BASE_URL: process.env.CYPRESS_UAM_BASE_URL,
      CYPRESS_UAM_BASIC_AUTH: process.env.CYPRESS_UAM_BASIC_AUTH,
    },
  },
});

Could someone help me understand why the environment variables are not being retrieved and how to resolve this issue?

I was expecting that by writing npx nx run ${{ inputs.repo_project_name }}:e2e this command end to end test will run fine

I tried passing --env in the command, and it worked fine. However, if there are more than four environment variables, the command would become unwieldy. Is there a better approach to handle this?
<p>In my GitHub Actions CI/CD pipeline, there is a step for Cypress end-to-end tests that uses the command <code>npx nx run ${{ inputs.repo_project_name }}:e2e</code>.</p>
<p>My end-to-end tests are failing because they are unable to retrieve environment variables. The end-to-end tests run successfully locally but fail to execute in the CI/CD GitHub Actions environment.</p>
<p>Here is my Cypress configuration file:</p>
<pre><code>import { defineConfig } from 'cypress';
import { nxE2EPreset } from '@nx/cypress/plugins/cypress-preset';
import { nxComponentTestingPreset } from '@nx/next/plugins/component-testing';

export default defineConfig({
component: {
...nxComponentTestingPreset(__filename),
},
e2e: {
...nxE2EPreset(__filename, { cypressDir: 'cypress' }),
baseUrl: 'http://localhost:4201',
pageLoadTimeout: 100000,
env: {
JDC_ALIAS: 'http://localhost:4201',
CYPRESS_UAM_BASE_URL: process.env.CYPRESS_UAM_BASE_URL,
CYPRESS_UAM_BASIC_AUTH: process.env.CYPRESS_UAM_BASIC_AUTH,
},
},
});
</code></pre>
<p>Could someone help me understand why the environment variables are not being retrieved and how to resolve this issue?</p>
<p>I was expecting that by writing <code>npx nx run ${{ inputs.repo_project_name }}:e2e</code> this command end to end test will run fine</p>
<p>I tried passing <code>--env</code> in the command, and it worked fine. However, if there are more than four environment variables, the command would become unwieldy. Is there a better approach to handle this?</p>
Continue reading...
 

Latest posts

Top