-
Notifications
You must be signed in to change notification settings - Fork 12
/
CI.Jenkinsfile
73 lines (68 loc) · 2.69 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
// These are Debian images.
def php_versions = [8.1, 8.2, 8.3]
def runVersion(sourceDir, ver) {
mySonarOpts = "-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.
// There is an equivalent check in CI.sh. Update both!!!!
// The coverage tool version we are using doesn't like 8.2.
// TODO: Add CS Fixer Execution somewhere in CI.sh during the 8.2 extras.
if (ver == 8.1) {
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 /php-source && \
/root/sonar-scanner-4.8.1.3023-linux/bin/sonar-scanner ${mySonarOpts}"
} else {
sonarExec = "echo Skipping Sonar for this version."
}
echo "Testing PHP version ${ver}"
sh "docker run --rm \
--pull always \
-e ROSETTE_API_KEY=${env.ROSETTE_API_KEY} \
-v ${sourceDir}:/php-source \
php:${ver}-cli \
bash -c \"cd /php-source && \
./CI.sh && \
${sonarExec} && \
echo && \
echo [INFO] Re-permission files for cleanup. && \
chown -R 9960:9960 /php-source\""
}
node ("docker-light") {
def sourceDir = pwd()
try {
stage("Clean up") {
step([$class: 'WsCleanup'])
}
stage("Checkout Code") {
checkout scm
}
stage("Build and Test") {
withSonarQubeEnv {
php_versions.each { ver ->
runVersion(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)
}