forked from eficode-academy/jenkins-katas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
98 lines (92 loc) · 2.07 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
pipeline {
agent any
environment {
docker_username = 'amrutashety'
}
stages {
stage('Clone Down'){
agent {
label 'swarm'
}
steps{
stash excludes: '.git', name: 'code'
}
}
stage('Parallel Execution') {
parallel {
stage('Hello') {
steps {
sh 'echo "hello world"'
}
}
stage('Build app') {
agent {
docker {
image 'gradle:6-jdk11'
}
}
options {
skipDefaultCheckout true
}
steps {
unstash 'code'
sh 'ci/build-app.sh'
archiveArtifacts 'app/build/libs/'
stash excludes: '.git', name: 'code'
}
}
stage('Test app') {
agent {
docker {
image 'gradle:6-jdk11'
}
}
options {
skipDefaultCheckout true
}
steps {
unstash 'code'
sh 'ci/unit-test-app.sh'
junit 'app/build/test-results/test/TEST-*.xml'
}
}
}
}
stage('Push Docker App'){
agent {
label 'swarm'
}
when {
beforeAgent true
branch "master"
}
environment {
DOCKERCREDS = credentials('docker_login') //use the credentials just created in this stage
}
steps {
unstash 'code' //unstash the repository code
sh 'ci/build-docker.sh'
sh 'echo "$DOCKERCREDS_PSW" | docker login -u "$DOCKERCREDS_USR" --password-stdin' //login to docker hub with the credentials above
sh 'ci/push-docker.sh'
}
}
stage('Component testing'){
agent {
label 'swarm'
}
when {
beforeAgent true
not { branch 'dev/*' }
}
steps {
unstash 'code' //unstash the repository code
sh 'ci/component-test.sh'
}
}
}
post {
cleanup {
deleteDir() /* clean up our workspace */
}
}
}