forked from feedhenry/fh-pipeline-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
executable file
·156 lines (132 loc) · 4.95 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
#!/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) {
step([$class: 'WsCleanup'])
print "#### test_${name} ####"
body()
}
}
node {
env.BRANCH_NAME = env.BRANCH_NAME ?: 'master'
String gitref = env.CHANGE_ID ? "pr/${env.CHANGE_ID}" : env.BRANCH_NAME
def fhPipelineLibrary = library("fh-pipeline-library@${gitref}")
def utils = fhPipelineLibrary.org.feedhenry.Utils.new()
testStage('getReleaseBranch') {
print utils.getReleaseBranch('1.2.3')
}
testStage('getReleaseTag') {
print utils.getReleaseTag('1.2.3')
}
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]:feedhenry/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('stashComponentArtifacts') {
def componentName = getTestComponentName()
def componentConfig = getTestComponentConfigs()[componentName]
stashComponentArtifacts(componentName, 'master', componentConfig['buildJobName'])
}
testStage('unstashComponentArtifacts') {
def componentName = getTestComponentName()
unstashComponentArtifacts(componentName) { v, b ->
def componentVersion = v
def componentBuild = b
print componentVersion
print componentBuild
}
}
}