-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathbuild.groovy
More file actions
62 lines (50 loc) · 2.06 KB
/
Copy pathbuild.groovy
File metadata and controls
62 lines (50 loc) · 2.06 KB
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
import hudson.model.*
node {
deleteDir()
def groovy_scripts_path = 'jenkins-pipeline-groovy'
stage('bootstrap') {
dir(groovy_scripts_path) {
sh """
git clone git@github.com:OGProgrammer/jenkins-pipeline-groovy.git --branch=master .
"""
}
dir(groovy_scripts_path) {
functions = load("functions.groovy")
}
}
stage("prep") {
// Get Jenkins Parameters
def env_name = "${env_name}"
def app_name = "${app_name}"
// Get variables from the application manifest
def applicationManifest = functions.getApplicationManifest(env_name, app_name)
def app_repo = applicationManifest.app_repo
def docker_repo = applicationManifest.docker_repo
// Global param, accessible in other stage nodes
image_name = applicationManifest.image_name
applicationManifest = null
// Other parameters needed
image_tag = "${env.BUILD_ID}-${env_name}"
tagged_image_name = "${image_name}:${image_tag}"
docker_build_file = "dockerfiles/${env_name}/Dockerfile"
println "Building the app [name:${app_name}, repo:${app_repo}] with the docker image [name:${image_name}, repo:${docker_repo}] on the [${env_name}] environemnt."
git poll: true, url: "${docker_repo}", branch: "${env_name}"
// Clone the app repo into the directory that will be packed into our docker image
dir("files/var/www/${app_name}") {
git url: "${app_repo}", branch: "${env_name}"
}
}
stage('build') {
sh "docker build -f ${docker_build_file} -t ${tagged_image_name} ./"
}
stage('publish') {
// Push the docker image tags up to docker hub
sh """
docker tag ${tagged_image_name} ${image_name}:latest
docker push ${tagged_image_name}
docker push ${image_name}:latest
"""
// Save the build id (version) tag to our manifest repo
functions.setLatestBuild(env_name, app_name, image_name, image_tag)
}
}