-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy path.gitlab-ci.yml
103 lines (96 loc) · 3.44 KB
/
.gitlab-ci.yml
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
image: appirio/dx-java:latest
stages:
- build
- quality_scan
- deploy
- rollback
variables:
JAR_LOCATION: "sonar-apex-plugin/target/*.jar"
BACKUP_LOCATION: "apex-plugin-backup.jar"
CODE_COVERAGE: "coverage"
SONAR_PLUGIN_LOCATION: "sonar-plugins/apex-plugin.jar"
build_new_plugin:
stage: build
script:
- mvn package -Dbuild.number=$CI_PIPELINE_ID
cache:
key: $CI_PIPELINE_ID
paths:
- apex-checks/target/
- apex-squid/target/
- apex-toolkit/target/
- sonar-apex-plugin/target/
artifacts:
name: "CI_COMMIT_REF_NAME/$CI_JOB_ID"
paths:
- $JAR_LOCATION
when: on_success
expire_in: 1 week
sonarqube_publish:
stage: quality_scan
script:
- sonar-scanner
-Dsonar.host.url=https://sonar.appirio.com
-Dsonar.login=$SONAR_LOGIN
-Dsonar.projectKey=$CI_PROJECT_PATH_SLUG
-Dsonar.links.scm=$CI_PROJECT_URL
-Dsonar.projectVersion=$CI_PIPELINE_ID
-Dsonar.java.binaries=$CI_PROJECT_DIR/apex-checks/target/,$CI_PROJECT_DIR/apex-squid/target/,$CI_PROJECT_DIR/apex-toolkit/target/,$CI_PROJECT_DIR/sonar-apex-plugin/target/
-Dsonar.junit.reportPaths=$CI_PROJECT_DIR/apex-checks/target/surefire-reports,$CI_PROJECT_DIR/apex-squid/target/surefire-reports,$CI_PROJECT_DIR/sonar-apex-plugin/target/surefire-reports
-Dsonar.jacoco.reportPaths=$CI_PROJECT_DIR/apex-checks/target/jacoco.exec,$CI_PROJECT_DIR/apex-squid/target/jacoco.exec,$CI_PROJECT_DIR/sonar-apex-plugin/target/jacoco.exec
-Dsonar.gitlab.ref_name=$CI_COMMIT_REF_NAME
-Dsonar.gitlab.max_blocker_issues_gate=5
-Dsonar.gitlab.max_critical_issues_gate=5
cache:
key: $CI_PIPELINE_ID
paths:
- apex-checks/target/
- apex-squid/target/
- apex-toolkit/target/
- sonar-apex-plugin/target/
backup_and_update:
stage: deploy
when: manual
script:
- echo "$HOST_KEY" >> known_hosts
- echo "$SONAR_SERVER_KEY" > sonar.key
- chmod 600 sonar.key
- echo "========"
- echo "Backing up the existing plugin"
- scp -i sonar.key -o "UserKnownHostsFile known_hosts" $SONAR_SERVER_USER@$SONAR_SERVER_IP:$SONAR_PLUGIN_LOCATION $BACKUP_LOCATION
- echo "========"
- echo "Publishing the new plugin"
- scp -i sonar.key -o "UserKnownHostsFile known_hosts" $JAR_LOCATION $SONAR_SERVER_USER@$SONAR_SERVER_IP:$SONAR_PLUGIN_LOCATION
- echo "========"
- echo "Restarting the server"
- ssh -i sonar.key -o "UserKnownHostsFile known_hosts" $SONAR_SERVER_USER@$SONAR_SERVER_IP 'sudo ./sonar-ctl.sh restart &>/dev/null &'
artifacts:
name: $CI_PIPELINE_ID/backup
paths:
- $BACKUP_LOCATION
when: on_success
expire_in: 1 week
restore_plugin_from_backup:
stage: rollback
when: manual
script:
- echo "$HOST_KEY" >> known_hosts
- echo "$SONAR_SERVER_KEY" > sonar.key
- chmod 600 sonar.key
- ls $BACKUP_LOCATION
- echo "========"
- echo "Writing backup plugin to server"
- scp -i sonar.key -o "UserKnownHostsFile known_hosts" $BACKUP_LOCATION $SONAR_SERVER_USER@$SONAR_SERVER_IP:$SONAR_PLUGIN_LOCATION
- echo "========"
- echo "Restarting the server"
- ssh -i sonar.key -o "UserKnownHostsFile known_hosts" $SONAR_SERVER_USER@$SONAR_SERVER_IP 'sudo ./sonar-ctl.sh restart &>/dev/null &'
dependencies:
- backup_and_update
.build_folders: &cache_builds
cache:
key: $CI_COMMIT_REF_SLUG
paths:
- apex-checks/target/
- apex-squid/target/
- apex-toolkit/target/
- sonar-apex-plugin/target/