Jenkinsfile-gitlab 3.2 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// Comments

pipeline {
    agent {
        label 'bellatrix'
    }
    options {
        disableConcurrentBuilds()
        timestamps()
        gitLabConnection('OAI GitLab')
        //gitlabBuilds(builds: ["Build", "Test"])
    }

    stages {
        stage ("Verify Parameters") {
            steps {
                echo 'Verify Parameters'
                echo "Git URL         is ${GIT_URL}"
                echo "GitLab Act      is ${env.gitlabActionType}"
                script {
                    if ("MERGE".equals(env.gitlabActionType)) {
                        // GitLab-Jenkins pugin integration is lacking to perform the merge by itself
                        // Doing it manually --> it may have merge conflicts
24
25
                        sh "./ci-scripts/doGitLabMerge.sh ${env.gitlabSourceBranch} ${env.gitlabMergeRequestLastCommit} ${env.gitlabTargetBranch} ${GIT_COMMIT}"
                        sh "./ci-scripts/checkCodingFormattingRules.sh ${env.gitlabSourceBranch} ${env.gitlabTargetBranch}"
26
27
28
29
30
31
32
33
34
                        def res=readFile('./oai_rules_result.txt').trim();
                        if ("0".equals(res)) {
                            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"
                        }
                    } else {
                        echo "Git Branch      is ${GIT_BRANCH}"
                        echo "Git Commit      is ${GIT_COMMIT}"
35
                        sh "./ci-scripts/checkCodingFormattingRules.sh"
36
37
38
39
40
41
42
                    }
                }
            }
        }
    }
    post {
        always {
43
44
45
            script {
                echo "End of script"
            }
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
        }
        success {
            script {
                def message = "OAI build #" + BUILD_ID + " passed (" + BUILD_URL + ")"
                if ("MERGE".equals(env.gitlabActionType)) {
                    echo "This is a MERGE event"
                    addGitLabMRComment comment: message
                    def message2 = "OAI build #" + BUILD_ID + " passed (" + BUILD_URL + ") -- MergeRequest #" + env.gitlabMergeRequestIid + " (" + env.gitlabMergeRequestTitle + ")"
                    slackSend channel: 'ci-enb', color: 'good', message: message2
                } else {
                    slackSend channel: 'ci-enb', color: 'good', message: message
                }
            }
        }
        failure {
            script {
                def message = "OAI build #" + BUILD_ID + " failed (" + BUILD_URL + ")"
                if ("MERGE".equals(env.gitlabActionType)) {
                    echo "This is a MERGE event"
                    addGitLabMRComment comment: message
                    def message2 = "OAI build #" + BUILD_ID + " failed (" + BUILD_URL + ") -- MergeRequest #" + env.gitlabMergeRequestIid + " (" + env.gitlabMergeRequestTitle + ")"
                    slackSend channel: 'ci-enb', color: 'danger', message: message2
                } else {
                    slackSend channel: 'ci-enb', color: 'danger', message: message
                }
            }
        }
    }
}