-
Notifications
You must be signed in to change notification settings - Fork 9
/
Jenkinsfile
executable file
·190 lines (156 loc) · 6.26 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#!/usr/bin/groovy
import org.kohsuke.github.GHOrganization
import org.kohsuke.github.GHUser
import org.kohsuke.github.GitHub
import org.kohsuke.github.GitHubBuilder
final boolean isOrgMember(String user, String org, String gitHubCredentialsId) {
node {
withCredentials([usernamePassword(
credentialsId: gitHubCredentialsId,
passwordVariable: 'GITHUB_PASSWORD',
usernameVariable: 'GITHUB_USERNAME')]) {
final GitHub gitHub = new GitHubBuilder()
.withOAuthToken(env.GITHUB_PASSWORD, env.GITHUB_USERNAME)
.build()
final GHUser ghUser = gitHub.getUser(user)
final GHOrganization ghOrganization = gitHub.getOrganization(org)
return ghUser.isMemberOf(ghOrganization)
}
}
}
stage('Trust') {
/*
* This is copied from 'enforceTrustedApproval',
* because using that here would not be trustworthy
*/
if (!env.CHANGE_AUTHOR) {
println "This doesn't look like a GitHub PR, continuing"
} else if (!isOrgMember(env.CHANGE_AUTHOR, 'fheng', 'githubjenkins')) {
input(
message: "Trusted approval needed for change from ${env.CHANGE_AUTHOR}",
submitter: 'authenticated'
)
} else {
println "${env.CHANGE_AUTHOR} is trusted, continuing"
}
}
def getTestComponentName() {
return 'fh-mbaas'
}
def getTestComponentConfigs() {
def componentConfigs = [:]
def componentName = getTestComponentName()
componentConfigs[componentName] = [:]
componentConfigs[componentName]['gitHubOrg'] = 'feedhenry'
componentConfigs[componentName]['repoName'] = 'fh-mbaas'
componentConfigs[componentName]['baseBranch'] = 'master'
componentConfigs[componentName]['repoDir'] = ''
componentConfigs[componentName]['cookbook'] = 'fh-mbaas'
componentConfigs[componentName]['buildType'] = 'node'
componentConfigs[componentName]['distCmd'] = 'grunt fh:dist'
componentConfigs[componentName]['buildJobName'] = "build_any_jenkinsfile"
componentConfigs[componentName]['gitUrl'] = "[email protected]:feedhenry/fh-mbaas.git"
componentConfigs[componentName]['gitHubUrl'] = "https://github.com/feehdenry/fh-mbaas"
return componentConfigs
}
def testStage(name, body) {
stage(name) {
cleanWs()
print "#### test_${name} ####"
body()
}
}
node {
def fhPipelineLibrary = library("fh-pipeline-library@${env.BRANCH_NAME}")
def utils = fhPipelineLibrary.org.feedhenry.Utils.new()
testStage('getReleaseBranch') {
print utils.getReleaseBranch('1.2.3')
}
testStage('gitRepoIsDirty') {
sh "mkdir repotest && cd repotest && git init"
dir("repotest") {
print "Default gitRepoIsDirty works?"
print utils.gitRepoIsDirty()
print "Override untrackedFiles in gitRepoIsDirty works?"
print utils.gitRepoIsDirty('normal')
print "Default thisGitRepoIsDirty works?"
print utils.thisGitRepoIsDirty(this)
print "Override untrackedFiles in thisGitRepoIsDirty works?"
print utils.thisGitRepoIsDirty(this, 'normal')
print "Static thisGitRepoIsDirty works?"
print fhPipelineLibrary.org.feedhenry.Utils.thisGitRepoIsDirty(this)
print "Static thisGitRepoIsDirty with untrackedFiles override works?"
print fhPipelineLibrary.org.feedhenry.Utils.thisGitRepoIsDirty(this, 'normal')
}
sh "rm -rf repotest"
}
testStage('getReleaseTag') {
print utils.getReleaseTag('1.2.3')
}
testStage('getVersionString') {
assert utils.getVersionString('1.2.3', '') == '1.2.3'
assert utils.getVersionString('1.2.3', null) == '1.2.3'
assert utils.getVersionString('1.2.3', '1234567') == '1.2.3-1234567'
assert utils.getVersionString('', '1234567') == '1234567'
assert utils.getVersionString(null, '1234567') == '1234567'
}
testStage('getArtifactsDir') {
print utils.getArtifactsDir('fh-ngui')
}
testStage('checkoutGitRepo') {
checkoutGitRepo {
repoUrl = '[email protected]:feedhenry/fh-pipeline-library.git'
branch = 'master'
}
sh('ls')
}
testStage('eachComponent') {
def allComponents = [getTestComponentName()]
def componentConfigs = getTestComponentConfigs()
eachComponent(allComponents, componentConfigs) { name, gitHubOrg, gitUrl, gitHubUrl, config ->
print name
print gitHubOrg
print gitUrl
print gitHubUrl
print config
}
}
testStage('getComponentConfigs') {
def configGitRepo = "[email protected]:fheng/product_releases.git"
def configGitRef = 'master'
def componentConfigs = getComponentConfigs(configGitRepo, configGitRef)
print componentConfigs
}
testStage('getTemplateAppComponentConfigs') {
def configGitRepo = "[email protected]:feedhenry/fh-template-apps.git"
def configGitRef = 'master'
def componentConfigs = getTemplateAppComponentConfigs(configGitRepo, configGitRef)
print componentConfigs
}
testStage('fhcapNode') {
fhcapNode(gitRepo: '[email protected]:fheng/fhcap-cli.git', gitRef: 'master') {
print env.PATH
sh "fhcap --version"
sh "fhcap info"
sh "openssl version"
sh "nova --version 2>&1 | grep 7.1.0"
sh "aws --version 2>&1 | grep 1.11.80"
sh "date"
}
}
testStage('Koji') {
String kojiUrl = "https://koji.fedoraproject.org/kojihub"
def koji = fhPipelineLibrary.org.feedhenry.Koji.new(kojiUrl)
// If this starts failing in a few years, update with a new build from here:
// https://koji.fedoraproject.org/koji/packageinfo?packageID=8
String name = "kernel"
String version = "4.15.2"
String release = "301.fc27"
Map<String, String> aKernelBuild = koji.awaitBuild("${name}-${version}-${release}")
println aKernelBuild
assert aKernelBuild.name == name
assert aKernelBuild.version == version
assert aKernelBuild.release == release
assert koji.listArchives(aKernelBuild.build_id) == []
}
}