Jenkinsfile 4.62 KB
Newer Older
Raphael Defosseux's avatar
Raphael Defosseux committed
1
// Comments
Raphael Defosseux's avatar
last???  
Raphael Defosseux committed
2
// author raphael defosseux
Raphael Defosseux's avatar
Raphael Defosseux committed
3
// 
4 5 6

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

    stages {
Raphael Defosseux's avatar
Raphael Defosseux committed
17
        stage ("Verify Parameters") {
18 19
            steps {
                echo 'Verify Parameters'
OAI Jenkins's avatar
OAI Jenkins committed
20
                //echo "Base URL        is ${JENKINS_URL}"
21 22
                echo "Git URL         is ${GIT_URL}"
                echo "GitLab Act      is ${env.gitlabActionType}"
Raphael Defosseux's avatar
Raphael Defosseux committed
23 24
                script {
                    if ("MERGE".equals(env.gitlabActionType)) {
OAI Jenkins's avatar
OAI Jenkins committed
25 26 27
                        //echo "GitLab src branch is ${env.gitlabSourceBranch}"
                        //echo "GitLab tar branch is ${env.gitlabTargetBranch}"
                        //echo "Git Last Commit is ${env.gitlabMergeRequestLastCommit}"
Raphael Defosseux's avatar
Raphael Defosseux committed
28 29
                        // GitLab-Jenkins pugin integration is lacking to perform the merge by itself
                        // Doing it manually --> it may have merge conflicts
OAI Jenkins's avatar
OAI Jenkins committed
30
                        sh "./scripts/doGitLabMerge.sh ${env.gitlabSourceBranch} ${env.gitlabMergeRequestLastCommit} ${env.gitlabTargetBranch} ${GIT_COMMIT}"
31
                        sh "./scripts/checkCodingFormattingRules.sh ${env.gitlabSourceBranch} ${env.gitlabTargetBranch}"
OAI Jenkins's avatar
OAI Jenkins committed
32
                        def res=readFile('./oai_rules_result.txt').trim();
OAI Jenkins's avatar
fixi  
OAI Jenkins committed
33
                        if ("0".equals(res)) {
OAI Jenkins's avatar
OAI Jenkins committed
34 35 36 37
                            addGitLabMRComment comment: "All Changed files in Merge Request follow OAI Formatting Rules"
                        } else {
                            addGitLabMRComment comment: "Some Changed files in Merge Request DO NOT follow OAI Formatting Rules"
                        }
Raphael Defosseux's avatar
Raphael Defosseux committed
38
                    } else {
OAI Jenkins's avatar
OAI Jenkins committed
39 40
                        echo "Git Branch      is ${GIT_BRANCH}"
                        echo "Git Commit      is ${GIT_COMMIT}"
41
                        sh "./scripts/checkCodingFormattingRules.sh"
Raphael Defosseux's avatar
Raphael Defosseux committed
42
                    }
Raphael Defosseux's avatar
Raphael Defosseux committed
43
                }
44 45
            }
        }
Raphael Defosseux's avatar
Raphael Defosseux committed
46
        stage ("Build") {
Raphael Defosseux's avatar
Raphael Defosseux committed
47 48
            steps {
                gitlabCommitStatus(name: "Build") {
Raphael Defosseux's avatar
Raphael Defosseux committed
49 50 51
                    sh "gcc src/test1.c -I./include -o bin/test1"
                    sh "gcc src/test2.c -I./include -o bin/test2"
                    sh "gcc src/test2.c -I./include -o bin/test3"
Raphael Defosseux's avatar
Raphael Defosseux committed
52
                    sh "cppcheck --enable=warning --force --xml --xml-version=2 src 2> cppcheck.xml"
53
                }
Raphael Defosseux's avatar
Raphael Defosseux committed
54
            }
Raphael Defosseux's avatar
Raphael Defosseux committed
55
        }
Raphael Defosseux's avatar
Raphael Defosseux committed
56
        stage ("Test") {
Raphael Defosseux's avatar
Raphael Defosseux committed
57 58
            steps {
                gitlabCommitStatus(name: "Test") {
Raphael Defosseux's avatar
Raphael Defosseux committed
59 60
                    sh "./bin/test1"
                    sh "./bin/test2"
Raphael Defosseux's avatar
Raphael Defosseux committed
61
                    sh "./bin/test3"
62
                }
Raphael Defosseux's avatar
Raphael Defosseux committed
63 64
            }
        }
65 66
        stage ("Test slave job") {
            steps {
Raphael Defosseux's avatar
again  
Raphael Defosseux committed
67 68
                build job: 'CI-Sandbox4-slave',
                   parameters: [
Raphael Defosseux's avatar
Raphael Defosseux committed
69 70 71
                       string(name: 'eNB_Repository', value: String.valueOf(GIT_URL)),
                       string(name: 'eNB_Branch', value: String.valueOf(GIT_BRANCH)),
                       string(name: 'eNB_CommitID', value: String.valueOf(GIT_COMMIT))
Raphael Defosseux's avatar
again  
Raphael Defosseux committed
72
                   ]
73 74
            }
        }
75
    }
76
    post {
Raphael Defosseux's avatar
Raphael Defosseux committed
77
        always {
Raphael Defosseux's avatar
Raphael Defosseux committed
78 79 80 81 82
            script {
                if(fileExists('cppcheck.xml')) {
                    archiveArtifacts artifacts: 'cppcheck.xml'
                }
            }
Raphael Defosseux's avatar
Raphael Defosseux committed
83 84 85
        }
        success {
            script {
Raphael Defosseux's avatar
Raphael Defosseux committed
86
                def message = "OAI build #" + BUILD_ID + " passed (" + BUILD_URL + ")"
Raphael Defosseux's avatar
Raphael Defosseux committed
87 88
                if ("MERGE".equals(env.gitlabActionType)) {
                    addGitLabMRComment comment: message
Raphael Defosseux's avatar
Raphael Defosseux committed
89
                    def message2 = "OAI build #" + BUILD_ID + " passed (" + BUILD_URL + ") -- MergeRequest #" + env.gitlabMergeRequestIid + " (" + env.gitlabMergeRequestTitle + ")"
Raphael Defosseux's avatar
Raphael Defosseux committed
90 91 92
                    slackSend channel: 'sandbox', color: 'good', message: message2
                } else {
                    slackSend channel: 'sandbox', color: 'good', message: message
Raphael Defosseux's avatar
Raphael Defosseux committed
93 94 95 96 97
                }
            }
        }
        failure {
            script {
Raphael Defosseux's avatar
Raphael Defosseux committed
98
                def message = "OAI build #" + BUILD_ID + " failed (" + BUILD_URL + ")"
Raphael Defosseux's avatar
Raphael Defosseux committed
99 100
                if ("MERGE".equals(env.gitlabActionType)) {
                    addGitLabMRComment comment: message
Raphael Defosseux's avatar
Raphael Defosseux committed
101
                    def message2 = "OAI build #" + BUILD_ID + " failed (" + BUILD_URL + ") -- MergeRequest #" + env.gitlabMergeRequestIid + " (" + env.gitlabMergeRequestTitle + ")"
Raphael Defosseux's avatar
Raphael Defosseux committed
102 103 104
                    slackSend channel: 'sandbox', color: 'danger', message: message2
                } else {
                    slackSend channel: 'sandbox', color: 'danger', message: message
Raphael Defosseux's avatar
Raphael Defosseux committed
105 106 107
                }
            }
        }
108
    }
109
}