[GITLAB] - UPGRADE TO v12 on Wednesday the 18th of December at 11.30AM

Jenkinsfile 3.41 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()
10
        gitLabConnection('OAI GitLab')
Raphael Defosseux's avatar
Raphael Defosseux committed
11
        gitlabBuilds(builds: ["Build", "Test"])
12 13 14
    }

    stages {
Raphael Defosseux's avatar
Raphael Defosseux committed
15
        stage ("Verify Parameters") {
16 17 18 19 20 21
            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
22 23 24 25 26 27 28 29 30
                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"
31
                    }
Raphael Defosseux's avatar
Raphael Defosseux committed
32
                }
33 34
            }
        }
Raphael Defosseux's avatar
Raphael Defosseux committed
35
        stage ("Build") {
36 37
            steps {
                gitlabCommitStatus(name: "Build") {
Raphael Defosseux's avatar
Raphael Defosseux committed
38 39
                    sh "gcc src/test1.c -o bin/test1"
                    sh "gcc src/test2.c -o bin/test2"
40
                    sh "gcc src/test2.c -o bin/test3"
Raphael Defosseux's avatar
Raphael Defosseux committed
41
                    sh "cppcheck --enable=warning --force --xml --xml-version=2 src 2> cppcheck.xml"
42
                }
43
            }
Raphael Defosseux's avatar
Raphael Defosseux committed
44
        }
Raphael Defosseux's avatar
Raphael Defosseux committed
45
        stage ("Test") {
46 47
            steps {
                gitlabCommitStatus(name: "Test") {
Raphael Defosseux's avatar
Raphael Defosseux committed
48 49
                    sh "./bin/test1"
                    sh "./bin/test2"
50
                    sh "./bin/test3"
51
                }
52 53
            }
        }
54
    }
55
    post {
56
        always {
Raphael Defosseux's avatar
Raphael Defosseux committed
57 58 59 60 61
            script {
                if(fileExists('cppcheck.xml')) {
                    archiveArtifacts artifacts: 'cppcheck.xml'
                }
            }
62 63 64
        }
        success {
            script {
65
                def message = "OAI build #" + BUILD_ID + " passed (" + BUILD_URL + ")"
66 67 68
                if ("MERGE".equals(env.gitlabActionType)) {
                    echo "This is a MERGE event"
                    addGitLabMRComment comment: message
Raphael Defosseux's avatar
Raphael Defosseux committed
69 70 71 72
                    def message2 = "OAI build #" + BUILD_ID + " passed (" + BUILD_URL + ") -- MergeRequest #" + env.gitlabMergeRequestId + " (" + env.gitlabMergeRequestTitle + ")"
                    slackSend channel: 'sandbox', color: 'good', message: message2
                } else {
                    slackSend channel: 'sandbox', color: 'good', message: message
73 74 75 76 77
                }
            }
        }
        failure {
            script {
78
                def message = "OAI build #" + BUILD_ID + " failed (" + BUILD_URL + ")"
79 80 81
                if ("MERGE".equals(env.gitlabActionType)) {
                    echo "This is a MERGE event"
                    addGitLabMRComment comment: message
Raphael Defosseux's avatar
Raphael Defosseux committed
82
                    def message2 = "OAI build #" + BUILD_ID + " failed (" + BUILD_URL + ") -- MergeRequest #" + env.gitlabMergeRequestId + " (" + env.gitlabMergeRequestTitle + ")"
Raphael Defosseux's avatar
Raphael Defosseux committed
83 84 85
                    slackSend channel: 'sandbox', color: 'danger', message: message2
                } else {
                    slackSend channel: 'sandbox', color: 'danger', message: message
86 87 88
                }
            }
        }
89
    }
90
}