1
- node {
2
-
3
- stage ' checkout project'
4
- // git url: 'https://github.com/agileworks-tw/spring-boot-sample.git'
5
- checkout scm
6
- stage ' check docker env'
7
-
8
- sh " docker -v"
9
- sh " docker-compose -v"
10
- sh " docker ps"
11
- sh " make start-docker-registry"
12
-
13
- stage ' build docker env'
14
- sh " make build-docker-env"
15
-
16
- stage ' test project'
17
- sh " docker-compose run --rm test"
18
-
19
- stage ' report'
20
- step([$class : ' JUnitResultArchiver' , testResults : ' **/target/surefire-reports/TEST-*.xml' ])
21
-
22
- stage ' Artifact'
23
- step([$class : ' ArtifactArchiver' , artifacts : ' **/target/*.jar' , fingerprint : true ])
24
-
25
- stage ' server project'
26
- sh " docker-compose up -d server"
27
-
28
- try {
29
- stage ' Approve, go production'
30
- def url = ' http://localhost:8000/'
31
- input message : " Does staging at $url look good? " , ok : " Deploy to production"
32
- }finally {
33
- sh " docker-compose stop server"
34
- }
35
-
36
- stage ' package project'
37
- sh " docker-compose run --rm package"
38
-
39
- stage ' build docker production image'
40
- sh " make build-docker-prod-image"
41
-
42
- stage ' publish docker production image'
43
- sh " docker push localhost:5000/java_sample_prod"
44
-
45
- try {
46
- sh " docker rm -f java_sample_prod"
47
- }catch (Exception ex) {
48
- println (" Catching the exception" );
49
- }
50
-
51
- stage ' deploy production'
52
- sh " make deploy-production-local"
53
-
54
- }
1
+ pipeline {
2
+ agent any
3
+ stages {
4
+ stage(' checkout project' ) {
5
+ steps {
6
+ // git url: 'https://github.com/agileworks-tw/spring-boot-sample.git'
7
+ checkout scm
8
+ }
9
+ }
10
+ stage(' check docker install and build env' ) {
11
+ steps {
12
+ sh " docker -v"
13
+ sh " docker-compose -v"
14
+ sh " docker ps"
15
+ sh " make start-docker-registry"
16
+ sh " make build-docker-env"
17
+ }
18
+ }
19
+ stage(' test project and serve' ) {
20
+ steps {
21
+ sh " docker-compose run --rm test"
22
+ step([$class : ' JUnitResultArchiver' , testResults : ' **/target/surefire-reports/TEST-*.xml' ])
23
+ step([$class : ' ArtifactArchiver' , artifacts : ' **/target/*.jar' , fingerprint : true ])
24
+ sh " docker-compose up -d server"
25
+ }
26
+ }
27
+ stage(' wait for confirm' ) {
28
+ input {
29
+ message " Does staging at http://localhost:8000 look good?"
30
+ ok " Deploy to production"
31
+ submitter " admin"
32
+ parameters {
33
+ string(name : ' PERSON' , defaultValue : ' Mr Jenkins' , description : ' Who should I say hello to?' )
34
+ }
35
+ }
36
+ steps {
37
+ echo " Hello, ${ PERSON} , nice to meet you."
38
+
39
+ }
40
+ post {
41
+ always {
42
+ sh " docker-compose stop server"
43
+ }
44
+ }
45
+ }
46
+ stage(' deploy project' ) {
47
+ when {
48
+ branch ' master'
49
+ }
50
+ steps {
51
+ sh " docker-compose run --rm package"
52
+ sh " make build-docker-prod-image"
53
+ sh " docker push localhost:5000/java_sample_prod"
54
+ sh " docker stop java_sample_prod || true && docker rm java_sample_prod || true"
55
+ }
56
+ post {
57
+ success {
58
+ sh " make deploy-production-local"
59
+ }
60
+ }
61
+ }
62
+ }
63
+ }
0 commit comments