简体   繁体   English

当 C++ 程序更改目录时,Gitlab CI 的行为不符合预期

[英]Gitlab CI doesn't behave as expected when c++ program changes directory

let's assume in my code there is a system process to do.让我们假设在我的代码中有一个系统进程要做。 However, i have to change directory before doing so and the going back, that step is necessary, no simple way to circumvent this operation.但是,我必须在这样做之前更改目录并返回,这一步是必要的,没有简单的方法来规避这个操作。

std::filesystem::current_directory("child/");
std::process::system(command);
std::filesystem::current_directory("../");

This works in my local machine, however, in my gitlab-ci runner, which runs in the same relative path as in local, it seems that is incapable of changing the current directory, and runs the command in the directory the script was placed:这适用于我的本地机器,但是,在我的 gitlab-ci 运行器中,它运行在与本地相同的相对路径中,似乎无法更改当前目录,并在放置脚本的目录中运行命令:

testing:
stage: testing
image: 
    #same OS and similar environment as local
    name: myhub/archlinux
script:
    - export BOOST_INCLUDEDIR="/usr/include/boost/"
    - export BOOST_LIBRARYDIR="/usr/lib/"
    - cd build/tests
    - ./buildUStests

Is there a way to tell the runner to be more flexible when the program demands to change the current directory?当程序需要更改当前目录时,有没有办法告诉跑步者更加灵活? Or do i have to use another way to make the runner change directories?还是我必须使用另一种方式来让跑步者改变目录?

Sorry for the confusion, I actually found the issue.对不起,我真的发现了这个问题。

GitLab and git essentially don't incorporate empty directories, which my program relies on, into my repo. GitLab 和 git 基本上不会将我的程序所依赖的空目录合并到我的 repo 中。

This means that if I roll my tests without knowing that behavior, it seems as if my program refuses to change directory.这意味着如果我在不知道该行为的情况下滚动测试,似乎我的程序拒绝更改目录。

The solution to the problem is to create the directory at execution, then make the shell commands.解决问题的方法是在执行时创建目录,然后制作 shell 命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM