Compile and test a C application

Using Codefresh pipelines

Codefresh can work with any C/C++ application very easily as both gcc and g++ are already offered in Dockerhub. There is also another example available with C++ and cmake.

The example C project

You can see the example project at https://github.com/codefresh-contrib/c-sample-app. The repository contains a C starter project with a Makefile and several targets:

  • make compiles the code.
  • make test runs unit tests
  • make clean removes artifacts and binaries.

There are also extra targets for tags and etags.

Create a CI pipeline for C applications

Creating a CI/CD pipeline for C is very easy, because Codefresh can run any gcc image that you wish. Gcc docker images already contain the make utility.

Compiling a C application in a pipeline

Compiling a C application in a pipeline

Here is the full pipeline that compiles the application after checking out the code.

codefresh.yml

version: '1.0'
stages:
  - checkout
  - build
steps:
  main_clone:
    title: Cloning main repository...
    stage: checkout
    type: git-clone
    repo: 'codefresh-contrib/c-sample-app'
    revision: master
    git: github
  compile_my_sources:
    title: Compile
    stage: build
    image: gcc
    commands:
      - make
  run_my_tests:
    title: Test
    stage: build
    image: gcc
    commands:
      - make test   

This pipeline clones the source code, compiles the code and runs unit tests. In all cases we use the public Docker image of Gcc that also contains make.

C++ example
Codefresh YAML for pipeline definitions
Steps in pipelines
Creating pipelines
How Codefresh pipelines work