-
Notifications
You must be signed in to change notification settings - Fork 11
/
CI.Jenkinsfile
107 lines (99 loc) · 3.86 KB
/
CI.Jenkinsfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
def versions = [3.0, 3.1, 3.2, 3.3]
def runSonnarForPythonVersion(sourceDir, ver){
mySonarOpts="-Dsonar.sources=/source -Dsonar.host.url=${env.SONAR_HOST_URL} -Dsonar.login=${env.SONAR_AUTH_TOKEN}"
if("${env.CHANGE_ID}" != "null"){
mySonarOpts = "$mySonarOpts -Dsonar.pullrequest.key=${env.CHANGE_ID} -Dsonar.pullrequest.branch=${env.BRANCH_NAME}"
} else {
mySonarOpts = "$mySonarOpts -Dsonar.branch.name=${env.BRANCH_NAME}"
}
if ("${env.CHANGE_BRANCH}" != "null") {
mySonarOpts="$mySonarOpts -Dsonar.pullrequest.base=${env.CHANGE_TARGET} -Dsonar.pullrequest.branch=${env.CHANGE_BRANCH}"
}
// Only run Sonar once.
// Check for new versions at https://binaries.sonarsource.com/?prefix=Distribution/sonar-scanner-cli/
if(ver == 3.3) {
sonarExec="cd /root/ && \
wget -q https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.8.1.3023-linux.zip && \
unzip -q sonar-scanner-cli-4.8.1.3023-linux.zip && \
cd /source && \
/root/sonar-scanner-4.8.1.3023-linux/bin/sonar-scanner ${mySonarOpts}"
} else {
sonarExec="echo Skipping Sonar for this version."
}
//
//
// NOTE: The test coverage data is not making it into Sonar.
// I don't think it is worth spending more time on until
// Sonar is upgraded.
//
//
sh "docker run \
--pull always \
--rm --volume ${sourceDir}:/source \
ruby:${ver}-slim \
bash -c \"echo && \
echo [INFO] Testing with Ruby ${ver} && \
echo && \
echo [INFO] Updating package manager database. && \
apt-get update -qq && \
echo && \
echo [INFO] Installing required OS packages. && \
apt-get -qq install -y gcc make wget unzip > /dev/null && \
echo && \
echo [INFO] Installing gems needed for CI. && \
gem install --silent --quiet bundler rspec rubocop && \
cd /source && \
echo && \
echo [INFO] Running rubocop. && \
rubocop && \
echo && \
echo [INFO] Running bundle install. && \
bundle install --quiet && \
echo && \
echo [INFO] Removing any coverage data from prior executions. && \
rm -rf coverage && \
echo [INFO] Running unit tests. && \
rspec tests && \
echo && \
echo [INFO] Building gem. && \
gem build rosette_api.gemspec && \
echo && \
echo [INFO] Installing gem. && \
gem install rosette_api-*.gem && \
echo && \
echo [INFO] Executing Sonar if required. && \
${sonarExec} && \
echo && \
echo [INFO] Re-permission files for cleanup. && \
chown -R jenkins:jenkins /source\""
}
node ("docker-light") {
def sourceDir = pwd()
try {
stage("Clean up") {
step([$class: 'WsCleanup'])
}
stage("Checkout Code") {
checkout scm
}
stage("Build & Test") {
withSonarQubeEnv {
versions.each { ver ->
runSonnarForPythonVersion(sourceDir, ver)
}
}
}
postToTeams(true)
} catch (e) {
currentBuild.result = "FAILED"
postToTeams(false)
throw e
}
}
def postToTeams(boolean success) {
def webhookUrl = "${env.TEAMS_PNC_JENKINS_WEBHOOK_URL}"
def color = success ? "#00FF00" : "#FF0000"
def status = success ? "SUCCESSFUL" : "FAILED"
def message = "*" + status + ":* '${env.JOB_NAME}' - [${env.BUILD_NUMBER}] - ${env.BUILD_URL}"
office365ConnectorSend(webhookUrl: webhookUrl, color: color, message: message, status: status)
}