Calling CMake with Start-Process in GitLab CI job doesn’t appear to use passed arguments

I am very new to Powershell especially in the context of GitLab CI configuration.

My repo has the following structure:

*
|
+ - .gitlab-ci.yml
|
+ - CMakeLists.txt
|
+ - .gitmodules
|
+ - .configs
|      |
|      + - .basic_config.yml
|      |
|      + - .dep_1_config.yml
|      |
|     ...
|      |
|      + - .dep_N_config.yml
|
+ - deps
     |
     + - submodule_1
     |
    ...
     |
     + - submodule_N

In my CMakeLists.txt I add (based on a -D flag for the CMake command call) each submodule 1..N with add_subdirectory("${CMAKE_SOURCE_DIR}/deps/submodule_X").

The .configs directory contains a basic CI configuration used by all others and a single configuration file per dependency (represented by a corresponding git submodule, e.g. .dep_3_config.yml takes care of the CI configuration for submodule_3). All dependency configs are then called inside the main gitlab-ci.yml.

.basic_config.yml

# Currently used only for experimentation
.build-setup:
  before_script:
    - git config --system core.longpaths true

# The main base configuration for any building CI job
.build:
  variables:
    DepName: ""
    # DepCmakeArg will be overwritten by inheriting CI config of a dependency and set to the CMake cmd arguments required for its configuration
    DepCmakeArg: -DBuildDEFAULT=ON
  rules:
    - if: $CI_COMMIT_REF_NAME == "debug" | $CI_COMMIT_REF_NAME == "main"
  script:
    - |
      New-Item -Path "." -Name "build" -ItemType "directory"
      
      # main == release but we have to rename it to keep it consistent
      # This check should be dropped in the future (perhaps) for the tag
      # check and proper release (special type of CI job)
      if($env:CI_COMMIT_REF_NAME -eq "main"){
        $env:CI_COMMIT_REF_NAME = "release"
      }
    
      # Configuration step with CMake
      Start-Process cmake -ArgumentList "-Bbuild -G ""Visual Studio 16 2019"" -S$PWD -DCMAKE_CONFIGURATION_TYPES=""$env:CI_COMMIT_REF_NAME"" $env:DepCmakeArg" -NoNewWindow

      # Building step with CMake
      Start-Process cmake -ArgumentList "--build build --target ALL_BUILD --config $env:CI_COMMIT_REF_NAME" -NoNewWindow

# Sets up the artifacts directory to ensure common structure for all artifacts so that they can be easily integrated as dependencies in other projects
.artifact-setup:
  variables:
    DepName: "DEFAULT"  # Will be overriden by the local CI job variable with the same name
    ArtifactRoot: "artifacts"
  script:
    - |
      if($CI_COMMIT_REF_NAME -eq "main"){
        $ArtifactRoot = "${ArtifactRoot}/release"
      }else{
        $ArtifactRoot = "${ArtifactRoot}/${CI_COMMIT_REF_NAME}"
      }
      mkdir -p ${ArtifactRoot}lib
      mkdir -p ${ArtifactRoot}bin
      mkdir -p ${ArtifactRoot}include${DepName}

# Copy the artifacts from ArtifactRoot to a specific location set by ArtifactRootCopyDestination
# Can be used e.g. to provide artifacts locally to CI jobs instead of forcing those to trigger download
.artifact-copy:
  script:
    - |
      Copy-Item -Path "$env:ArtifactRoot" -Destination "$env:ArtifactRootCopyDestination" -Recurse -Container:$true -force
      Get-Date | Out-File "$env:ArtifactRootCopyDestination/$env:CI_COMMIT_REF_NAME/artifacts.txt" -NoNewLine -Force

An example for a dependency is OpenCV, which I build (using some CMake variables inside my CMakeLists.txt:

.opencv_config.yml

# Add base configuration
include:
  - local: .configs/.base_config.yml

.build-opencv:
  stage: build
  variables:
    DepName: opencv
    # Specifying CMAKE_INSTALL_PREFIX makes sure that the generated artifacts are referencing relatively the installation dir
    # In case of OpenCV if not used and even if the files are properly copied, the ".cmake" config files inside the installed
    # lib dir will reference <opencv-install-dir>/<arch>/<compiler>
    DepCmakeArg: -DBuildOpenCV=ON -DCMAKE_INSTALL_PREFIX="./install/"
    ArtifactRoot: !reference [.artifact-setup, variables, ArtifactRoot]
    GIT_SUBMODULE_STRATEGY: recursive
    GIT_SUBMODULE_PATHS: deps/opencv
    ArtifactRootCopyDestination: "${COMMON_DEPS}/opencv/4.10.0/cpu/"
  artifacts:
    # Upload everything until issue fixed
    untracked: true
    #paths:
    #  - artifacts
    #  - "./deps/build/*"
    when: always
  script:
    - ls
    - !reference [.build, script]

The call for that dependency inside my CI configuration:

.gitlab-ci.yml

stages:
  - build

include:
  - local: .configs/.opencv_config.yml

build-opencv-release:
  stage: build
  rules:
    - if: $CI_COMMIT_REF_NAME == "main"
  variables: !reference [.build-opencv, variables]
  artifacts: !reference [.build-opencv, artifacts]
  script:
    - !reference [.build-opencv, script]

I had it all working until I started adding the command line arguments for CMake with the option to adjust those using CI variables. Then I was forced to switch from just calling CMake, e.g.

script:
  - cmake -Bbuild -G "Visual Studio 16 2019" -S. ..........

to using a multiline script as described in my .basic_config.yml.

When I run the CI job I get

$ # Main == release but we have to rename it to keep it consistent # collapsed multi-line command
-- Selecting Windows SDK version 10.0.17763.0 to target Windows 10.0.14393.
Error: could not load cache
...

without the actual building step producing any binaries (that was not the case before I switched to Start-Process!).

I am not sure what’s going on.

PS: The ArtifactRootCopyDestination is for creating a local copy of the artifact. Some of the dependencies produce artifacts that are too big to upload so project that are using those have the option to use a local version (everything is stored and executed on an executor I have set up myself so the CI has access to these resources).

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật