简体   繁体   English

我需要帮助为C ++设置.gitlab-ci.yml文件

[英]I need help setting up a .gitlab-ci.yml file for C++

The GitLab documentation is lacking and not very clear. GitLab文档缺乏而且不太清楚。 How do I setup this file to automatically build my C++ project (it will tell you if it passes or fails) and how do I configure to have separate builds for Windows/Mac/Linux. 如何设置此文件以自动构建我的C ++项目(它将告诉您它是否通过)以及如何配置为Windows / Mac / Linux单独构建。 If you need me to share my repo with you just ask. 如果您需要我与您分享我的回购,请问。

Before you automate anything run it manually. 在自动化之前,手动运行它。 Write a shell script then put that in CI. 编写一个shell脚本,然后将其放入CI中。 Below is a simple template using the shell executor. 下面是一个使用shell执行器的简单模板。

before_script:
   - export BUILD_VAR=if_needed

build_linux:
   stage: build
   script:
      - my_build_script.sh

If your steps are simple you can put them directly in the CI config: 如果您的步骤很简单,可以直接将它们放在CI配置中:

build_linux:
   stage: build
   script:
      - ./configure
      - make

Get that working for your simplest case and then grow it from there. 让它适用于最简单的情况,然后从那里开始。

To build a C++ application, you will need a compiler. 要构建C ++应用程序,您需要一个编译器。 You can use an existing Docker image that has a compiler. 您可以使用具有编译器的现有Docker镜像。 I'm using the gcc image here. 我在这里使用gcc图像。

Here is my .gitlab-ci.yml file. 这是我的.gitlab-ci.yml文件。 You don't have to use CMake , just put in whatever commands you need to build your application and make sure you've satisfied the build dependencies in the image. 您不必使用CMake ,只需输入构建应用程序所需的任何命令,并确保您已满足映像中的构建依赖性。

# Use the official gcc image
image: gcc

before_script:
    # Install build dependencies
    - apt-get update && apt-get -y install cmake

myapp:
    # Build the application
    stage: build
    script:
        - mkdir build
        - cd build
        - cmake ..
        - make

That should be enough to get you started. 这应该足以让你开始。

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

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