简体   繁体   中英

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

The GitLab documentation is lacking and not very clear. 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. 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. Below is a simple template using the shell executor.

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:

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. You can use an existing Docker image that has a compiler. I'm using the gcc image here.

Here is my .gitlab-ci.yml file. 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.

# 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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