Home > front end >  Azure Pipeline returns "undefined" in filepath
Azure Pipeline returns "undefined" in filepath

Time:03-10

I am running my e2e WebdriverIO on Gitlab Pipeline. Now I am trying to integrate my e2e tests after the deployment on Azure. The tests run after deployment as expected, only that I have a strange error with Azure.

I have a test case to upload a file. Here is how I get the file:

const filePath = process.env.PWD   '/test/resources/files/logo.jpg'
console.log('file = '   filePath);

When my tests run on Gitlab Pipeline, the file can be located as follow:

file = /builds/hw2yvbjx/0/xxx/xxx/xxx/xxx/e2e/test/resources/files/logo.jpg

But when my tests run on Azure Pipeline, the file is undefined as follow:

file = undefined/test/resources/files/logo.jpg

and the full log is as follow:

Error: ENOENT: no such file or directory, open 'C:\azagent\xxx\xxx\xxx\xxx\_xxx\e2e\undefined\test\resources\files\logo.jpg'

The path is correct, except that extra undefined is added between e2e and test. Does anyone know why this undefined is appended in the path? And how to fix it?

Thanks

CodePudding user response:

process.env.PWD will log as undefined on Windows. The PWD environment variable is a 'Linux thing'.

That's why you're seeing this in your log statement in Azure (running on Windows, deduced based on the path starting with C:\...) but not in your GitLab job, which runs on a Linux host.

To fix it, you can use process.cwd(), which is platform agnostic, instead of process.env.PWD.

  • Related