forked from redhat-developer-demos/12factor-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
70 lines (60 loc) · 3.03 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
podTemplate(
inheritFrom: "maven",
label: "myJenkins",
cloud: "openshift",
volumes: [
persistentVolumeClaim(claimName: "m2repo", mountPath: "/home/jenkins/.m2/")
]) {
node("myJenkins") {
stage("Git Checkout") {
echo "Checking out git repository"
checkout scm
}
stage("Build") {
echo 'Building project'
sh "mvn package"
}
stage("DEV - Image Release") {
echo 'Building docker image and deploying to Dev'
sh "oc new-project 12factor-dev || echo 'Project exists'"
sh "oc policy add-role-to-user admin developer -n 12factor-dev"
sh "oc project 12factor-dev"
sh "oc new-build -n 12factor-dev --binary --name=my12factorapp || echo 'Build exists'"
sh "oc start-build my12factorapp -n 12factor-dev --from-dir=. --follow"
}
stage ("DEV - App RUN"){
sh "oc new-app my12factorapp -n 12factor-dev || echo 'Aplication already Exists'"
sh "oc expose service my12factorapp -n 12factor-dev || echo 'Service already exposed'"
sh "oc set probe dc/my12factorapp -n 12factor-dev --readiness --get-url=http://:8080/api/health"
}
stage("Automated tests") {
echo 'This stage simulates automated tests'
sh "mvn -B -Dmaven.test.failure.ignore verify"
}
stage("QA - App RUN") {
echo 'Deploying to QA'
sh "oc new-project 12factor-qa || echo 'Project exists'"
sh "oc policy add-role-to-user admin developer -n 12factor-qa"
sh "oc project 12factor-qa"
sh "oc policy add-role-to-user system:image-puller system:serviceaccount:12factor-qa:default -n 12factor-dev"
sh "oc tag 12factor-dev/my12factorapp:latest 12factor-qa/my12factorapp:latest"
sh "oc new-app my12factorapp -n 12factor-qa || echo 'Aplication already Exists'"
sh "oc expose service my12factorapp -n 12factor-qa || echo 'Service already exposed'"
sh "oc set probe dc/my12factorapp -n 12factor-qa --readiness --get-url=http://:8080/api/health"
}
stage("Approve to PROD") {
input 'Approve to production?'
}
stage("PROD - App RUN") {
echo 'Deploying to production'
sh "oc new-project 12factor || echo 'Project exists'"
sh "oc policy add-role-to-user admin developer -n 12factor"
sh "oc project 12factor"
sh "oc policy add-role-to-user system:image-puller system:serviceaccount:12factor:default -n 12factor-qa"
sh "oc tag 12factor-qa/my12factorapp:latest 12factor/my12factorapp:latest"
sh "oc new-app -n 12factor --name my12factorapp my12factorapp || echo 'Aplication already Exists'"
sh "oc expose service my12factorapp -n 12factor || echo 'Service already exposed'"
sh "oc set probe dc/my12factorapp -n 12factor --readiness --get-url=http://:8080/api/health"
}
}
}