[英]Python script that calls vcvarsall.bat fails from GitLab CI
I have a Python script that works from cmd.exe
and powershell.exe
but not from a GitLab runner job on Windows. I have a Python script that works from
cmd.exe
and powershell.exe
but not from a GitLab runner job on Windows.
def build():
for c in ["Debug", "Release"]:
subprocess.check_call(
f'vcvarsall.bat x64 && \
cmake -G "NMake Makefiles" \
-B{os.path.dirname(os.path.realpath(__file__))}/src/x64/{c} \
-S{os.path.dirname(os.path.realpath(__file__))}/src \
-DCMAKE_BUILD_TYPE={c} & \
cmake --build {os.path.dirname(os.path.realpath(__file__))}/src/x64/{c}',
)
if __name__ == "__main__":
build()
If I run the script from cmd.exe
or powershell.exe
like so: python build.py
, everything works as expected - vcvarsall.bat
sets up the environment correctly so the subsequent cmake
call has all of the required environment variables. If I run the script from
cmd.exe
or powershell.exe
like so: python build.py
, everything works as expected - vcvarsall.bat
sets up the environment correctly so the subsequent cmake
call has all of the required environment variables.
Running the script from a GitLab runner job on Windows using the .gitlab-ci.yml
below fails.使用下面的
.gitlab-ci.yml
在 Windows 上从 GitLab 运行程序作业运行脚本失败。
build:
stage: build
script:
- python build.py
tags:
- windows
In the GitLab UI job stdout, I can confirm vcvarsall.bat
is being run and cmake
after that:在 GitLab UI 作业标准输出中,我可以确认
vcvarsall.bat
正在运行,然后是cmake
:
In the CMakeError.log
, the following error is reported:在
CMakeError.log
中,报错如下:
The above link error makes me think that running vcvarsall.bat
from the GitLab runner job is not completely configuring the environment - it is changing the environment, but not enough to make the subsequent cmake
complete successfully.上面的链接错误让我觉得从 GitLab runner 作业运行
vcvarsall.bat
并没有完全配置环境 - 它正在更改环境,但不足以使后续的cmake
成功完成。 I can see many differences between the environment configured by vcvarsall.bat
when executed from the GitLab runner job and cmd.exe
.当从 GitLab 运行器作业和
cmd.exe
执行时,我可以看到vcvarsall.bat
配置的环境之间存在许多差异。
For example, the left is the environment defined when running the script from the GitLab runner job, and the right from cmd.exe
:例如,左侧是从 GitLab 运行器作业运行脚本时定义的环境,右侧是从
cmd.exe
运行脚本时定义的环境:
Why do these environmental discrepancies exist, and how can I fix them?为什么会存在这些环境差异,我该如何解决?
The GitLab runner jobs will not inherit user environment variables or profiles. GitLab 运行器作业不会继承用户环境变量或配置文件。 For example, powershell on Windows runners is always run with the
NoProfile
switch.例如,Windows 跑步者上的 powershell 始终使用
NoProfile
开关运行。
You must add the variables explicitly in the runner configuration (or anywhere else env variables can be defined) or add them to system environment variables您必须在运行器配置中显式添加变量(或任何其他可以定义环境变量的地方)或将它们添加到系统环境变量中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.