文件路径中的 Azure Pipeline returns "undefined"

Azure Pipeline returns "undefined" in filepath

我正在 运行在 Gitlab 管道上安装我的 e2e WebdriverIO。现在我正在尝试在 Azure 上部署后集成我的 e2e 测试。按预期部署后测试 运行,只是我在 Azure 中遇到一个奇怪的错误。

我有一个上传文件的测试用例。这是我获取文件的方式:

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

当我在 Gitlab Pipeline 上测试 运行 时,文件可以位于如下位置:

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

但是当我在 Azure Pipeline 上测试 运行 时,文件 undefined 如下:

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

完整日志如下:

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

路径是正确的,只是在e2etest之间添加了额外的undefined。有谁知道为什么这个 undefined 附加在路径中?以及如何修复它?

谢谢

process.env.PWD 将在 Windows 上记录为未定义。 PWD 环境变量是 'Linux thing'.

这就是为什么您会在 Azure 的日志语句中看到这一点(运行 on Windows,根据以 C:\... 开头的路径推导出来),但在您的 GitLab 作业中却看不到,在 Linux 主机上运行。

要修复它,您可以使用与平台无关的 process.cwd(),而不是 process.env.PWD