-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathCI.Jenkinsfile
65 lines (58 loc) · 2.24 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
def versions = [3.9, 3.10, 3.11, 3.12, 3.13]
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/
sonarScannerVersion="6.2.1.4610-linux-x64"
if(ver == 3.13) {
sonarExec="cd /root/ && \
wget -q https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${sonarScannerVersion}.zip && \
unzip -q sonar-scanner-cli-${sonarScannerVersion}.zip && \
cd /source && \
/root/sonar-scanner-${sonarScannerVersion}/bin/sonar-scanner ${mySonarOpts}"
} else {
sonarExec="echo Skipping Sonar for this version."
}
sh "docker run \
--pull always \
--rm --volume ${sourceDir}:/source \
python:${ver}-slim \
bash -c \"apt-get update && \
apt-get install -y wget unzip && \
pip3 install tox && \
cd /source && \
tox && \
${sonarExec} && \
echo && \
echo [INFO] Re-permission files for cleanup. && \
chown -R 9960:9960 /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)
}
}
}
} catch (e) {
currentBuild.result = "FAILED"
throw e
}
}