Jenkinsfile 3.82 KB
Newer Older
1
2
3
/*
** Variables.
*/
4
<<<<<<< HEAD
5
def serie = '20.10'
6
7
8
9
=======
properties([buildDiscarder(logRotator(numToKeepStr: '10'))])
def serie = '21.10'
>>>>>>> 192b7a4 (fix(ci) Using right sonarqube instance to analyse code (#30))
10
11
12
13
14
15
16
17
18
def maintenanceBranch = "${serie}.x"
if (env.BRANCH_NAME.startsWith('release-')) {
  env.BUILD = 'RELEASE'
} else if ((env.BRANCH_NAME == 'master') || (env.BRANCH_NAME == maintenanceBranch)) {
  env.BUILD = 'REFERENCE'
} else {
  env.BUILD = 'CI'
}

19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
def buildBranch = env.BRANCH_NAME
if (env.CHANGE_BRANCH) {
  buildBranch = env.CHANGE_BRANCH
}

/*
** Functions
*/

def isStableBuild() {
  return ((env.BUILD == 'RELEASE') || (env.BUILD == 'REFERENCE'))
}

def checkoutCentreonBuild(buildBranch) {
  def getCentreonBuildGitConfiguration = { branchName -> [
    $class: 'GitSCM',
    branches: [[name: "refs/heads/${branchName}"]],
    doGenerateSubmoduleConfigurations: false,
    userRemoteConfigs: [[
      $class: 'UserRemoteConfig',
      url: "ssh://git@github.com/centreon/centreon-build.git"
    ]]
  ]}

  dir('centreon-build') {
    try {
      checkout(getCentreonBuildGitConfiguration(buildBranch))
    } catch(e) {
      echo "branch '${buildBranch}' does not exist in centreon-build, then fallback to master"
      checkout(getCentreonBuildGitConfiguration('master'))
    }
  }
}

53
54
55
/*
** Pipeline code.
*/
56
57
58
59
60
stage('Source') {
  node {
    dir('centreon-connector') {
      checkout scm
    }
61
    checkoutCentreonBuild(buildBranch)
62
    sh "./centreon-build/jobs/connector/${serie}/mon-connector-source.sh"
63
    source = readProperties file: 'source.properties'
64
65
66
67
68
69
70
71
    publishHTML([
      allowMissing: false,
      keepAll: true,
      reportDir: 'summary',
      reportFiles: 'index.html',
      reportName: 'Centreon Connector Build Artifacts',
      reportTitles: ''
    ])
72
73
74
75
76
77
    env.VERSION = "${source.VERSION}"
    env.RELEASE = "${source.RELEASE}"
  }
}

try {
78
  stage('Sonar analysis') {
79
    parallel 'centos7': {
80
      node {
81
        sh 'setup_centreon_build.sh'
82
/*
83
        sh './centreon-build/jobs/connector/${serie}/mon-connector-unittest.sh centos7'
84
85
86
87
88
89
90
91
        step([
          $class: 'XUnitBuilder',
          thresholds: [
            [$class: 'FailedThreshold', failureThreshold: '0'],
            [$class: 'SkippedThreshold', failureThreshold: '0']
          ],
          tools: [[$class: 'GoogleTestType', pattern: 'ut.xml']]
        ])
92
93
*/
        if ((env.BUILD == 'RELEASE') || (env.BUILD == 'REFERENCE')) {
94
          withSonarQubeEnv('SonarQubeDev') {
95
96
97
            sh "./centreon-build/jobs/connector/${serie}/mon-connector-analysis.sh"
          }
        }
98
      }
99
   }
100
101
102
103
104
105
106
107
108
    if ((currentBuild.result ?: 'SUCCESS') != 'SUCCESS') {
      error('Unit tests stage failure.');
    }
  }

  stage('Package') {
    parallel 'centos7': {
      node {
        sh 'setup_centreon_build.sh'
109
        sh "./centreon-build/jobs/connector/${serie}/mon-connector-package.sh centos7"
110
      }
111
112
113
114
115
116
    },
    'centos8': {
      node {
        sh 'setup_centreon_build.sh'
        sh "./centreon-build/jobs/connector/${serie}/mon-connector-package.sh centos8"
      }
117
118
119
120
121
    }
    if ((currentBuild.result ?: 'SUCCESS') != 'SUCCESS') {
      error('Package stage failure.');
    }
  }
122
123
124
125
126
127
128
129
130
131
132
133

  if ((env.BUILD == 'RELEASE') || (env.BUILD == 'REFERENCE')) {
    stage('Delivery') {
      node {
        sh 'setup_centreon_build.sh'
        sh "./centreon-build/jobs/connector/${serie}/mon-connector-delivery.sh"
      }
      if ((currentBuild.result ?: 'SUCCESS') != 'SUCCESS') {
        error('Delivery stage failure.');
      }
    }
  }
134
135
136
}
finally {
  buildStatus = currentBuild.result ?: 'SUCCESS';
137
  if ((buildStatus != 'SUCCESS') && ((env.BUILD == 'RELEASE') || (env.BUILD == 'REFERENCE'))) {
138
139
140
    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."
  }
}