简体   繁体   中英

How can I run multiple builds in parallel in Travis CI, each with a separate script, for a C++ project?

I have a C++ project for which I would like to automate builds using Travis CI.

The project uses GNU make to build. There are multiple build targets, which are independent of each other, and I would like to automate the check that the build succeeds for each target using Travis CI. So, I would like multiple Travis builds to run for each commit, one for each target.

One way I could do this is:

script:
    - make target1
    - make target2
    - make target3

However, this could potentially hide problems, such as the case where the build of target2 succeeds only when target1 has already been built.

An alternative could then be:

script:
    - make target1
    - make clean
    - make target2
    - make clean
    - make target3

This looks a bit ugly, and also could take more time than needed. Errors in the build of target3 cannot be found till target1 and target2 are successfully built.

A better way might be to use the build matrix feature of Travis, which is what I have been unable to do. I tried the following:

matrix:
    - script: make target1
    - script: make target2
    - script: make target3

But this doesn't work. The Travis documentation for C++ suggests that a matrix can interleave different environments and compilers , and I am not able to find any way to run different scripts separately. Can this be specified with the environment in some way?

Is this possible? If so, what is the correct way to do this?

Thank you.

I have found the solution. Information on this is given in the Travis Docs here , and information specific to Makefiles is given here .

The solution that worked for me is:

env:
    matrix:
      - TARGET="target1"
      - TARGET="target2"
      - TARGET="target3"
script:
    - make $TARGET

This creates three jobs that run in parallel.

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