-
Notifications
You must be signed in to change notification settings - Fork 5
/
Jenkinsfile
159 lines (148 loc) · 4.48 KB
/
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
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
ios.prepareEnv(xcode: "/Applications/Xcode_10.2.app")
// Unlock Bitbucket Server credentials for Danger
def unlockBitbucketDangerCredentials(block) {
withCredentials([usernamePassword(credentialsId: 'pgs-software-bitbucket-server-danger_user', passwordVariable: 'DANGER_BITBUCKETSERVER_PASSWORD', usernameVariable: 'DANGER_BITBUCKETSERVER_USERNAME')]) {
block()
}
}
def unlockGitHubDangerCredentials(block) {
withCredentials([usernamePassword(credentialsId: 'pgs-github-PGSJenkins-token', passwordVariable: 'DANGER_GITHUB_API_TOKEN', usernameVariable: '')]) {
block()
}
}
// Repository detection
def job = env.JOB_NAME.tokenize("/")[0]
def unlockDangerCredentials = this.&unlockBitbucketDangerCredentials
if (job =~ /.*github.*/) {
echo "Repo: GitHub"
unlockDangerCredentials = this.&unlockGitHubDangerCredentials
} else {
echo "Repo: Bitbucket"
}
// Prepare
// - reset simulators
def prepareStage() {
stage("Prepare") {
sh '''
# Reset simulators
bundle exec fastlane snapshot reset_simulators --force --ios 12.0
'''
}
}
// Perform tests
def testStage(scheme, platform, deviceName, deviceOS) {
stage("${deviceName} ${deviceOS}") {
withEnv(["SCHEME=${scheme}", "PLATFORM=${platform}", "DESTINATION_NAME=${deviceName}", "DESTINATION_OS=${deviceOS}"]) {
try {
sh '''
bundle exec fastlane test "scheme:${SCHEME}" "destination:platform=${PLATFORM},name=${DESTINATION_NAME},OS=${DESTINATION_OS}"
'''
}
finally {
try {
sh '''
bundle exec golden_rose generate "output/AutoMate-AppBuddy.test_result"
mv "index.html" "output/index_${DESTINATION_NAME}_${DESTINATION_OS}.html" || true
mv "output/report.html" "output/report_${DESTINATION_NAME}_${DESTINATION_OS}.html" || true
'''
} finally {}
ios.archive()
publishHTML([
allowMissing: true,
alwaysLinkToLastBuild: true,
keepAll: true,
reportDir: 'output',
reportFiles: "report_${DESTINATION_NAME}_${DESTINATION_OS}.html",
reportName: "Report ${DESTINATION_NAME} ${DESTINATION_OS}"
])
publishHTML([
allowMissing: true,
alwaysLinkToLastBuild: true,
keepAll: true,
reportDir: 'output',
reportFiles: "index_${DESTINATION_NAME}_${DESTINATION_OS}.html",
reportName: "Golden Rose ${DESTINATION_NAME} ${DESTINATION_OS}"
])
}
}
}
}
// Test branch
def testBranch(scheme, platform, deviceName, deviceOS, unlockDanger=null) {
ios.runOniOSNode(nodeName: "ios_ui", runBlock: {
try {
prepareStage()
testStage(scheme, platform, deviceName, deviceOS)
} finally {
if (unlockDanger) {
unlockDanger() {
stage("Danger") {
sh '''
# Danger
bundle exec danger
'''
}
}
}
}
})
}
// CocoaPods lint branch
def podLintBranch() {
ios.runOniOSNode(runBlock: {
prepareStage()
stage("CocoaPods lint") {
sh '''
bundle exec pod lib lint
'''
}
})
}
// Carthage lint branch
def carthageLintBranch() {
ios.runOniOSNode(runBlock: {
prepareStage()
stage("Carthage lint") {
sh '''
carthage build --no-skip-current
'''
}
})
}
// Branches
def branches(unlockDanger) {
return [
"iPhone SE, 12.0": {
testBranch("AutoMate-AppBuddy", "iOS Simulator", "iPhone SE", "12.0")
},
"iPhone 8, 12.0": {
testBranch("AutoMate-AppBuddy", "iOS Simulator", "iPhone 8", "12.0")
},
"iPhone 8 Plus, 12.0": {
testBranch("AutoMate-AppBuddy", "iOS Simulator", "iPhone 8 Plus", "12.0")
},
"iPhone X, 12.0": {
testBranch("AutoMate-AppBuddy", "iOS Simulator", "iPhone X", "12.0", unlockDanger)
},
"iPad Air 2, 12.0": {
testBranch("AutoMate-AppBuddy", "iOS Simulator", "iPad Air 2", "12.0")
},
"iPad Pro (9.7-inch), 12.0": {
testBranch("AutoMate-AppBuddy", "iOS Simulator", "iPad Pro (9.7-inch)", "12.0")
},
"iPad Pro (10.5-inch), 12.0": {
testBranch("AutoMate-AppBuddy", "iOS Simulator", "iPad Pro (10.5-inch)", "12.0")
},
"iPad Pro (12.9-inch) (2nd generation), 12.0": {
testBranch("AutoMate-AppBuddy", "iOS Simulator", "iPad Pro (12.9-inch) (2nd generation)", "12.0")
},
"CocoaPods lint": {
podLintBranch()
},
"Carthage lint": {
carthageLintBranch()
}
]
}
// Parallel execution
parallel branches(unlockDangerCredentials)