-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathJenkinsfile
More file actions
142 lines (123 loc) · 5.41 KB
/
Jenkinsfile
File metadata and controls
142 lines (123 loc) · 5.41 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
properties([pipelineTriggers([
[$class: 'GitHubPushTrigger'], pollSCM('H/3 * * * *')
])])
def sendMail(userMail){
def logContent = Jenkins.getInstance()
.getItemByFullName(env.JOB_NAME)
.getBuildByNumber(Integer.parseInt(env.BUILD_NUMBER))
.logFile.text
// copy the log in the job's own workspace
writeFile file: "buildlog.txt", text: logContent
emailext (
attachmentsPattern: 'buildlog.txt',
subject: "FINISH: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'",
body: """
STARTED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}] ${env.BUILD_URL}':
Check console output at "${env.JOB_NAME} [${env.BUILD_NUMBER}]"
""",
to: userMail
)
}
node {
/*def committerEmail = sh (
script: 'git --no-pager show -s --format=\'%ae\'',
returnStdout: true
).trim();
def committerName = sh (
script: 'git --no-pager show -s --format=\'%an\'',
returnStdout: true
).trim();*/
def committerEmail = "onur.polat@mobven.com";
def committerName = "Onur POLAT";
def ts = "";
def PROJECT_ICON = "https://www.amchamksv.org/wp-content/uploads/2018/05/bkt.png";
def WORKSPACE = pwd();
// Git Configuration
def REPO_URL = "https://github.com/mobven/MobKit.git";
// SonarQube Configuration
def SONAR_PROJECT_KEY = "com.mobven.ios.mmb.sb";
def SONAR_PROJECT_NAME = "MMB_Kit";
def SONAR_KEY = "77e23545c9e2f20f96a93b0ffd8b83811471fcb3";
def SONAR_URL = "http://farm.mobven.com:9000";
def COVERAGE_PATH = "sonarqube-generic-coverage.xml";
def SLACK_DATA = "'${SONAR_PROJECT_NAME}' '${env.BUILD_NUMBER}' '${env.BUILD_URL}' '${committerName}' '${env.BRANCH_NAME}' '${PROJECT_ICON}'";
def SLACK_SH = "/Users/mobvenserver/.jenkins/workspace/slack-message-broker.sh";
stage('Preparation') {
try {
// Get code from a GitHub repository
git branch: env.BRANCH_NAME, credentialsId: 'SS', url: REPO_URL
ts = sh(script: "bash ${SLACK_SH} '${env.STAGE_NAME}' 0 ${SLACK_DATA}", returnStdout: true )
sh "rm -rf sonar-reports"
sh "rm -rf reports/*"
sh "cp /Users/mobvenserver/sonar-project.properties ."
} catch (e) {
sh "bash ${SLACK_SH} 'ErrorStage' '${ts}' ${SLACK_DATA}"
sendMail(committerEmail);
currentBuild.result = 'ABORTED'
error('Aborted due to a encountered error.')
}
}
stage ('Test') {
try {
sh "bash ${SLACK_SH} '${env.STAGE_NAME}' '${ts}' ${SLACK_DATA}"
sh "xcodebuild -scheme MobKitCore -sdk iphonesimulator -derivedDataPath Build/ -destination 'platform=iOS Simulator,name=iPhone 11,OS=13.4' test -enableCodeCoverage YES"
} catch (e) {
sh "bash ${SLACK_SH} 'ErrorStage' '${ts}' ${SLACK_DATA}"
sendMail(committerEmail);
currentBuild.result = 'ABORTED'
error('Aborted due to a encountered error.')
}
}
stage ('Coverage Generation') {
try {
sh "bash ${SLACK_SH} '${env.STAGE_NAME}' '${ts}' ${SLACK_DATA}"
sh "bash xccov-to-sonarqube-generic.sh Build/Logs/Test/*.xcresult/ > sonarqube-generic-coverage.xml"
} catch (e) {
sh "bash ${SLACK_SH} 'ErrorStage' '${ts}' ${SLACK_DATA}"
sendMail(committerEmail);
currentBuild.result = 'ABORTED'
error('Aborted due to a encountered error.')
}
}
stage ('Quality Check') {
try {
sh "bash ${SLACK_SH} '${env.STAGE_NAME}' '${ts}' ${SLACK_DATA}"
withSonarQubeEnv('LocalSonarQube'){ // SonarQube taskId is automatically attached to the pipeline context
sh "sonar-scanner -Dsonar.host.url=${SONAR_URL} -Dsonar.login=${SONAR_KEY} -Dsonar.projectKey=${SONAR_PROJECT_KEY} -Dsonar.coverageReportPaths=${COVERAGE_PATH} -Dsonar.cfamily.build-wrapper-output.bypass=true"
}
} catch (e) {
sh "bash ${SLACK_SH} 'ErrorStage' '${ts}' ${SLACK_DATA}"
sendMail(committerEmail);
currentBuild.result = 'ABORTED'
error('Aborted due to a encountered error.')
}
}
stage('Quality Gate'){
sh "bash ${SLACK_SH} '${env.STAGE_NAME}' '${ts}' ${SLACK_DATA}"
sleep(10) // Just in case something goes wrong, pipeline will be killed after a timeout
def qg = waitForQualityGate()
waitForQualityGate abortPipline: true // Reuse taskId previously collected by withSonarQubeEnv
if (qg.status != 'OK') {
sh "bash ${SLACK_SH} 'ErrorSQ2' '${ts}' ${SLACK_DATA}"
error "Pipeline aborted due to quality gate failure: ${qg.status}"
}
}
stage ('Jira') {
def commitMessage = sh (
script: 'git log --format=format:%s -1', // find commitMessage
returnStdout: true
).trim()
def regex = /[A-Z]{2,3}-\d{1,4}/
def commitMessageFormat = (commitMessage =~ regex).findAll() //convert format
String [] ary;
ary = commitMessageFormat //convert array
if (commitMessageFormat.size() == 0){
sh "bash ${SLACK_SH} 'Success' '${ts}' ${SLACK_DATA}"
} else {
for (String values : ary) {
sh "bash /Users/mobvenserver/.jenkins/workspace/Jira-Updater.sh '${values}'"
}
sh "bash ${SLACK_SH} 'Success' '${ts}' ${SLACK_DATA}"
}
}
}