-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathJenkinsfile
128 lines (106 loc) · 4.92 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
#!/usr/bin/env groovy
pipeline {
agent any
options {
buildDiscarder(logRotator(numToKeepStr: '5'))
}
parameters {
string(name: 'DOCKER_REPO', defaultValue: 'ngxp-seed', description: 'Docker Image name.')
string(name: 'DOCKER_TAG', defaultValue: 'latest', description: 'Docker Image tag.')
choice(name: 'VARIANT', choices: ['web'], description: 'Docker Image variant.')
choice(name: 'BUILD_ENV', choices: ['prod'], description: 'Build target environment.')
choice(name: 'CLIENT_LOCALE', choices: ['en', 'fr'], description: 'Client target locale.')
credentials(name: 'API_WEB_CREDENTIALS', credentialType: 'Username with password', required: true, description: 'Web Client API credentials.')
//credentials(name: 'PACKAGE_REPO_CREDENTIALS', credentialType: 'Username with password', required: true, description: 'Private Package Repository credentials to pull packages.')
string(name: 'DOCKER_REGISTRY', defaultValue: '', description: 'Docker Registry to publish the result image to. Leave empty for DockerHub.')
credentials(name: 'DOCKER_CREDENTIALS', credentialType: 'Username with password', required: true, description: 'Docker credentials to push on the Docker registry.')
}
triggers {
// Daily build, at 5 AM (server time), every business day
cron('H 5 * * 1-5')
}
stages {
stage('pending') {
steps {
updateGitlabCommitStatus name: 'jenkins', state: 'pending'
}
}
stage('check docker') {
steps {
sh "docker --version"
sh "docker-compose --version"
sh "docker info"
}
}
stage('build-hooks') {
environment {
//PACKAGE_REPO_CREDS = credentials("${PACKAGE_REPO_CREDENTIALS}")
API_CREDS = credentials("${API_WEB_CREDENTIALS}")
}
steps {
updateGitlabCommitStatus name: 'jenkins', state: 'running'
sh 'export API_WEB_CLIENT_ID=${API_CREDS_USR}; export API_WEB_CLIENT_SECRET=${API_CREDS_PSW}; export PACKAGE_REPO_LOGIN=${PACKAGE_REPO_CREDS_USR}; export PACKAGE_REPO_PASSWORD=${PACKAGE_REPO_CREDS_PSW}; ./hooks/run build "${VARIANT}"'
}
}
stage('test-hooks') {
steps {
updateGitlabCommitStatus name: 'jenkins', state: 'running'
sh './hooks/run test "${VARIANT}"'
}
}
stage('push-hooks') {
environment {
DOCKER_CREDS = credentials("${DOCKER_CREDENTIALS}")
}
steps {
updateGitlabCommitStatus name: 'jenkins', state: 'running'
// Write Docker image tags to push
sh '([ "${DOCKER_TAG}" = "latest" ] && echo "${VARIANT} " || echo "${DOCKER_TAG}-${VARIANT} ") > .dockertags'
// Export variables to login and push to Docker Registry
sh 'export DOCKER_LOGIN=${DOCKER_CREDS_USR}; export DOCKER_PASSWORD=${DOCKER_CREDS_PSW}; ./hooks/run push "${VARIANT}"'
sh 'rm -f .dockertags'
}
}
stage('build-hooks') {
environment {
NEXUS_CREDS = credentials("${NEXUS_CREDENTIALS}")
API_CREDS = credentials("${API_CREDENTIALS}")
}
steps {
updateGitlabCommitStatus name: 'jenkins', state: 'running'
sh 'export API_WEB_CLIENT_ID=${API_CREDS_USR}; export API_WEB_CLIENT_SECRET=${API_CREDS_PSW}; export NEXUS_LOGIN=${NEXUS_CREDS_USR}; export NEXUS_PASSWORD=${NEXUS_CREDS_PSW}; ./hooks/run build "${VARIANT}"'
}
}
stage('test-hooks') {
steps {
updateGitlabCommitStatus name: 'jenkins', state: 'running'
sh './hooks/run test "${VARIANT}"'
}
}
stage('push-hooks') {
environment {
DOCKER_CREDS = credentials("${DOCKER_CREDENTIALS}")
}
steps {
updateGitlabCommitStatus name: 'jenkins', state: 'running'
// Write Docker image tags to push
sh '([ "${DOCKER_TAG}" = "latest" ] && echo "${VARIANT} " || echo "${DOCKER_TAG}-${VARIANT} ") > .dockertags'
// Export variables to login and push to Docker Registry
sh 'export DOCKER_LOGIN=${DOCKER_CREDS_USR}; export DOCKER_PASSWORD=${DOCKER_CREDS_PSW}; ./hooks/run push "${VARIANT}"'
sh 'rm -f .dockertags'
}
}
}
post {
always {
// Always cleanup after the build.
sh 'docker image prune -f --filter until=$(date -d "yesterday" +%Y-%m-%d)'
}
success {
updateGitlabCommitStatus name: 'jenkins', state: 'success'
}
failure {
updateGitlabCommitStatus name: 'jenkins', state: 'failed'
}
}
}