Jenkinsfile 2.71 KB
Newer Older
Raphael Defosseux's avatar
Raphael Defosseux committed
1
// Comments
2 3 4

pipeline {
    agent {
Raphael Defosseux's avatar
Raphael Defosseux committed
5
        label 'bellatrix'
6 7 8 9
    }
    options {
        disableConcurrentBuilds()
        timestamps()
Raphael Defosseux's avatar
Raphael Defosseux committed
10
        gitlabBuilds(builds: ["Build", "Test"])
11 12 13 14 15 16 17 18 19 20
    }

    stages {
        stage ('Verify Parameters') {
            steps {
                echo 'Verify Parameters'
                echo "Base URL   is ${JENKINS_URL}"
                echo "Git Branch is ${GIT_BRANCH}"
                echo "Git Commit is ${GIT_COMMIT}"
                echo "Git URL    is ${GIT_URL}"
Raphael Defosseux's avatar
Raphael Defosseux committed
21 22 23 24 25 26 27 28 29 30 31
                echo "GitLab Act is ${env.gitlabActionType}"
                script {
                    if ("MERGE".equals(env.gitlabActionType)) {
                        echo "GitLab src branch is ${env.gitlabSourceBranch}"
                        echo "GitLab tar branch is ${env.gitlabTargetBranch}"
                        // GitLab-Jenkins pugin integration is lacking to perform the merge by itself
                        // Doing it manually --> it may have merge conflicts
                        sh "git merge --ff origin/${env.gitlabTargetBranch}"
                        sh "git log -n1"
                     }
                }
32 33
            }
        }
Raphael Defosseux's avatar
Raphael Defosseux committed
34 35
        stage ('Build') {
                steps {
Raphael Defosseux's avatar
Raphael Defosseux committed
36
            gitlabCommitStatus("Build") {
Raphael Defosseux's avatar
Raphael Defosseux committed
37 38 39
                    sh "gcc src/test1.c -o bin/test1"
                    sh "gcc src/test2.c -o bin/test2"
                    sh "cppcheck --enable=warning --force --xml --xml-version=2 src 2> cppcheck.xml"
40
                }
Raphael Defosseux's avatar
Raphael Defosseux committed
41
            }
Raphael Defosseux's avatar
Raphael Defosseux committed
42 43 44
        }
        stage ('Test') {
                steps {
Raphael Defosseux's avatar
Raphael Defosseux committed
45
            gitlabCommitStatus("Test") {
Raphael Defosseux's avatar
Raphael Defosseux committed
46 47
                    sh "./bin/test1"
                    sh "./bin/test2"
48
                }
Raphael Defosseux's avatar
Raphael Defosseux committed
49 50
            }
        }
51
    }
52
    post {
Raphael Defosseux's avatar
Raphael Defosseux committed
53 54 55 56 57 58 59
       always {
            script {
                if(fileExists('cppcheck.xml')) {
                    archiveArtifacts artifacts: 'cppcheck.xml'
                }
            }
       }
60
       success {
Raphael Defosseux's avatar
Raphael Defosseux committed
61 62 63 64 65 66 67 68 69 70 71
           script {
               if ("MERGE".equals(env.gitlabActionType)) {
                   echo "This is a MERGE event"
                   def msg = "OAI build #" + BUILD_ID + " passed"
                   echo "$msg"
                   addGitLabMRComment comment: msg
                   def message = "OAI build #" + BUILD_ID + " passed (" + BUILD_URL + ")"
                   echo "$message"
                   addGitLabMRComment comment: message
               }
           }
72
       }
Raphael Defosseux's avatar
Raphael Defosseux committed
73
       failure {
Raphael Defosseux's avatar
Raphael Defosseux committed
74 75 76 77 78 79 80
           script {
               if ("MERGE".equals(env.gitlabActionType)) {
                   echo "This is a MERGE event"
                   def message = "OAI build #" + BUILD_ID + " failed (" + BUILD_URL + ")"
                   addGitLabMRComment comment: message
               }
           }
81 82
       }
    }
83
}