Jenkinsfile 3.35 KB
Newer Older
1
2
3
/*
** Variables.
*/
4
def serie = '20.10'
5
def maintenanceBranch = "${serie}.x"
6
7
def qaBranch = "dev-${serie}.x"

8
9
10
11
if (env.BRANCH_NAME.startsWith('release-')) {
  env.BUILD = 'RELEASE'
} else if ((env.BRANCH_NAME == 'master') || (env.BRANCH_NAME == maintenanceBranch)) {
  env.BUILD = 'REFERENCE'
12
13
} else if ((env.BRANCH_NAME == 'develop') || (env.BRANCH_NAME == qaBranch)) {
  env.BUILD = 'QA'
14
15
16
17
} else {
  env.BUILD = 'CI'
}

18
19
20
/*
** Functions
*/
21
22
23
def buildBranch = env.BRANCH_NAME
if (env.CHANGE_BRANCH) {
  buildBranch = env.CHANGE_BRANCH
24
25
}

26
def checkoutCentreonBuild() {
27
  dir('centreon-build') {
28
29
30
31
32
    checkout resolveScm(source: [$class: 'GitSCMSource',
      remote: 'https://github.com/centreon/centreon-build.git',
      credentialsId: 'technique-ci',
      traits: [[$class: 'jenkins.plugins.git.traits.BranchDiscoveryTrait']]],
      targets: [BRANCH_NAME, 'master'])
33
34
35
  }
}

36
37
38
/*
** Pipeline code.
*/
39
stage('Source') {
40
  node("C++") {
41
42
43
    dir('centreon-connector') {
      checkout scm
    }
44
    checkoutCentreonBuild()
45
    sh "./centreon-build/jobs/connector/${serie}/mon-connector-source.sh"
46
    source = readProperties file: 'source.properties'
47
48
49
50
51
52
53
54
    publishHTML([
      allowMissing: false,
      keepAll: true,
      reportDir: 'summary',
      reportFiles: 'index.html',
      reportName: 'Centreon Connector Build Artifacts',
      reportTitles: ''
    ])
55
56
57
58
59
60
    env.VERSION = "${source.VERSION}"
    env.RELEASE = "${source.RELEASE}"
  }
}

try {
61
62
63
  stage('Packaging // Sonar analysis // Quality Gate') {
    parallel 'packaging centos7': {
      node("C++") {
64
        checkoutCentreonBuild()
65
        sh "./centreon-build/jobs/connector/${serie}/mon-connector-package.sh centos7"
66
67
        stash name: 'el7-rpms', includes: "output/x86_64/*.rpm"
        archiveArtifacts artifacts: "output/x86_64/*.rpm"
68
      }
Charles Gautier's avatar
Charles Gautier committed
69
70
    },
    'packaging alma8': {
71
      node("C++") {
72
        checkoutCentreonBuild()
Charles Gautier's avatar
Charles Gautier committed
73
74
        sh "./centreon-build/jobs/connector/${serie}/mon-connector-package.sh alma8"
        stash name: 'alma8-rpms', includes: "output/x86_64/*.rpm"
75
76
        archiveArtifacts artifacts: "output/x86_64/*.rpm"
      }
Charles Gautier's avatar
Charles Gautier committed
77
    },
78
79
    'Sonar analysis and Quality Gate': {
      node("C++") {
80
        checkoutCentreonBuild()
81
82
83
84
85
86
87
88
89
        withSonarQubeEnv('SonarQubeDev') {
          sh "./centreon-build/jobs/connector/${serie}/mon-connector-analysis.sh"
        }
      }  
    }
    timeout(time: 10, unit: 'MINUTES') {
      def qualityGate = waitForQualityGate()
      if (qualityGate.status != 'OK') {
        currentBuild.result = 'FAIL'
90
      }
91
92
    }
    if ((currentBuild.result ?: 'SUCCESS') != 'SUCCESS') {
93
      error('Packaging // Sonar analysis // Quality Gate failure');
94
95
    }
  }
96

97
  if ((env.BUILD == 'RELEASE') || (env.BUILD == 'QA')) {
98
    stage('Delivery') {
99
100
      node("C++") {
        unstash 'el7-rpms'
Charles Gautier's avatar
Charles Gautier committed
101
        unstash 'alma8-rpms'
102
        checkoutCentreonBuild()
103
104
105
106
107
108
109
        sh "./centreon-build/jobs/connector/${serie}/mon-connector-delivery.sh"
      }
      if ((currentBuild.result ?: 'SUCCESS') != 'SUCCESS') {
        error('Delivery stage failure.');
      }
    }
  }
110
111
112
}
finally {
  buildStatus = currentBuild.result ?: 'SUCCESS';
113
  if ((buildStatus != 'SUCCESS') && ((env.BUILD == 'RELEASE') || (env.BUILD == 'REFERENCE'))) {
114
115
116
    slackSend channel: '#monitoring-metrology', message: "@channel Centreon Connector build ${env.BUILD_NUMBER} of branch ${env.BRANCH_NAME} was broken by ${source.COMMITTER}. Please fix it ASAP."
  }
}