pipeline {
    environment {
        BUILDDIR = 'build-tests'
    }
    agent {
        dockerfile {
            dir 'automation'
            //force docker to redownload base image and rebuild all steps instead of caching them
            //this way, we always get an up to date docker image one each build
            additionalBuildArgs  '--no-cache --pull'
            reuseNode true
        }
    }
    stages {
        stage('Clean') {
            steps {
                sh 'rm -rf $BUILDDIR'
            }
        }
        stage('Configure') {
            steps {
                dir(BUILDDIR) {
                    sh 'cmake -DFSFW_OSAL=host -DFSFW_BUILD_UNITTESTS=ON ..'
                }
            }
        }
        stage('Build') {
            steps {
                dir(BUILDDIR) {
                    sh 'cmake --build . -j'
                }
            }
        }
        stage('Unittests') {
            steps {
                dir(BUILDDIR) {
                    sh 'cmake --build . -- fsfw-tests_coverage -j'
                }
            }
        }
        stage('Valgrind') {
            steps {
                dir(BUILDDIR) {
                    sh 'valgrind --leak-check=full --error-exitcode=1 ./fsfw-tests'
                }
            }
        }
    }
}