-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
91 lines (80 loc) · 2.16 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
pipeline {
agent none
environment {
PATH = "/usr/local/bin:/usr/bin:/usr/sbin:/bin:/sbin"
HOME = "."
}
options {
timestamps()
}
stages {
stage('Build') {
agent {
docker {
image 'adoptopenjdk/openjdk10:alpine'
args '--network=host'
}
}
steps {
sh './gradlew -x test clean build'
}
}
stage('Unit Test') {
agent {
docker {
image 'adoptopenjdk/openjdk10:alpine'
args '--network=host'
}
}
steps {
sh './gradlew test'
junit testResults: '**/build/test-results/**/*.xml', keepLongStdio: true, allowEmptyResults: false
}
}
stage('Prepare Container') {
agent {
docker {
image 'adoptopenjdk/openjdk10:alpine'
args '--network=host'
}
}
steps {
sh './gradlew -x test clean dockerCopy'
stash includes: 'build/docker/**/*', name: 'docker'
}
}
stage('Publish Container') {
agent any
when {
anyOf { branch 'master'; }
}
steps {
withCredentials([usernamePassword(
credentialsId: 'aws_jenkins',
usernameVariable: 'AWS_ACCESS_KEY_ID',
passwordVariable: 'AWS_SECRET_ACCESS_KEY'
)]) {
sh 'mkdir -p build/docker'
sh 'chmod -R u+w build/docker'
unstash 'docker';
sh 'rm ~/.dockercfg || true'
sh 'rm ~/.docker/config.json || true'
sh 'pip3 install awscli --user'
dir('build/docker') {
script {
//configure registry
sh("eval \$(aws ecr get-login --no-include-email --region us-east-1 | sed 's|https://||')")
docker.withRegistry('https://670848316581.dkr.ecr.us-east-1.amazonaws.com') {
//build image
def customImage = docker.build("neon/server:${env.BUILD_ID}")
//push image
customImage.push()
customImage.push('latest')
}
}
}
}
}
}
}
}