forked from ossimlabs/omar-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
144 lines (133 loc) · 4.04 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
properties([
buildDiscarder(logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '3', daysToKeepStr: '', numToKeepStr: '20')),
disableConcurrentBuilds(),
parameters([
booleanParam(name: 'CLEAN_WORKSPACE', defaultValue: true, description: 'Clean the workspace at the end of the run'),
string(name: 'DOCKER_REGISTRY_DOWNLOAD_URL', defaultValue: 'nexus-docker-private-group.ossim.io', description: 'Docker registry pull url.'),
string(name: 'BUILDER_VERSION', defaultValue: '2.2.1', description: 'Version of the docs-site-builder image to use.'),
string(name: 'VERSION', defaultValue: '', description: 'The version tag with which to build the docker image. Defaults to branch name, except on master.'),
text(name: 'ADHOC_PROJECT_YAML', defaultValue: '', description: 'Override the project vars used to generate documentation')
])
])
podTemplate(
containers: [
containerTemplate(
name: 'docker',
image: 'docker:latest',
ttyEnabled: true,
command: 'cat',
privileged: true
),
containerTemplate(
name: 'docs-site-builder',
image: "${DOCKER_REGISTRY_DOWNLOAD_URL}/docs-site-builder:${BUILDER_VERSION}",
command: 'cat',
ttyEnabled: true,
envVars: [
envVar(key: 'HOME', value: '/root')
]
),
containerTemplate(
image: "${DOCKER_REGISTRY_DOWNLOAD_URL}/alpine/helm:3.2.3",
name: 'helm',
command: 'cat',
ttyEnabled: true
)
],
volumes: [
hostPathVolume(
hostPath: '/var/run/docker.sock',
mountPath: '/var/run/docker.sock'
)
]
) {
node(POD_LABEL) {
stage("Checkout branch $BRANCH_NAME")
{
TAG = ''
if (BRANCH_NAME == "master") {
if (VERSION == '') {
print "Specify a version when building on master to release a docker image."
} else {
TAG = VERSION
}
} else {
TAG = BRANCH_NAME
}
checkout(scm)
}
container('docs-site-builder') {
stage("Copy files") {
sh """
cp -r /docs-site-builder/src .
"""
}
}
stage("Load Variables")
{
withCredentials([string(credentialsId: 'o2-artifact-project', variable: 'o2ArtifactProject')]) {
step ([$class: "CopyArtifact",
projectName: o2ArtifactProject,
filter: "common-variables.groovy",
flatten: true])
}
load "common-variables.groovy"
}
stage('Clone Repos') {
container('docs-site-builder') {
if (ADHOC_PROJECT_YAML != '') {
sh 'echo "${ADHOC_PROJECT_YAML}" > /docs-site-builder/omar-vars.yml'
}
sh """
python3 src/tasks/clone_repos.py -c omar-vars.yml
"""
}
}
stage('Build site') {
container('docs-site-builder') {
sh '''
python3 src/tasks/generate.py -c omar-vars.yml
'''
}
}
stage('Docker build') {
when (TAG != '') {
container('docker') {
sh """
docker build . -t ${DOCKER_REGISTRY_PRIVATE_UPLOAD_URL}/omar-docs:${TAG}
"""
}
}
}
stage('Docker push'){
when (TAG != '') {
container('docker') {
withDockerRegistry(credentialsId: 'dockerCredentials', url: "https://${DOCKER_REGISTRY_PRIVATE_UPLOAD_URL}") {
sh """
docker push ${DOCKER_REGISTRY_PRIVATE_UPLOAD_URL}/omar-docs:${TAG}
"""
}
}
}
}
stage('Package chart'){
container('helm') {
sh """
mkdir packaged-chart
helm package -d packaged-chart chart
"""
}
}
stage('Upload chart'){
container('docs-site-builder') {
withCredentials([usernameColonPassword(credentialsId: 'helmCredentials', variable: 'HELM_CREDENTIALS')]) {
sh "curl -u ${HELM_CREDENTIALS} ${HELM_UPLOAD_URL} --upload-file packaged-chart/*.tgz -v"
}
}
}
stage("Clean Workspace"){
if ("${CLEAN_WORKSPACE}" == "true")
step([$class: 'WsCleanup'])
}
}
}