
pipeline {
    agent none

    stages {
        stage('Build') {
            agent { 
		docker {
			image 'jenkins-build-agent:latest'
		}
	    }
            steps {
                echo 'Preparing..'
                cleanWs()
                echo 'Building..'
		sh './build.sh'
		archiveArtifacts artifacts: 'build/hello*', fingerprint: true
                echo 'Cleaning..'
		cleanWs cleanWhenFailure: false, cleanWhenNotBuilt: false, cleanWhenUnstable: false
            }
        }
        stage('Linting') {
            agent {
		dockerfile {
			filename 'Dockerfile.lint'
			reuseNode true
		}
	    }
            steps {
                echo 'Linting..'
		sh 'make tidy || true'
		//  junit allowEmptyResults: true, healthScaleFactor: 0.0, testResults: 'build/tidy.xml'
		sh 'true'
            }
        }
        stage('Test') {
            agent { docker 'jenkins-build-agent:latest' }
            steps {
                echo 'Testing..'
		sh 'make test || true'
		junit allowEmptyResults: true, healthScaleFactor: 0.0, testResults: 'build/tests.xml'
            }
        }
        stage('Deploy') {
            agent { docker 'jenkins-build-agent:latest' }
	    when {
              expression {
                currentBuild.result == null || currentBuild.result == 'SUCCESS' 
              }
            }
            steps {
            	echo 'Deploying....'
                sh 'make publish'
            }
        }
    }
}

