-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathJenkinsfile-groovy
More file actions
79 lines (58 loc) · 1.7 KB
/
Copy pathJenkinsfile-groovy
File metadata and controls
79 lines (58 loc) · 1.7 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import groovy.json.JsonOutput
import groovy.transform.Field
import groovy.json.JsonSlurper
node ('build-machinejava')
{
parameters
{
string(name: 'Service_Name', defaultValue: 'account-service', description: 'Which service needs to deploy')
choice(choices: 'develop\nrelease\nqa\nmaster', description: 'Select the Branch Name' , name: 'Branch_Name')
choice(choices: 'Dev\nPreProd\nProd', description: 'Select the runtime environment', name: 'Server_Environment')
}
if ("${BRANCH_NAME}" == 'master')
{
Checkout() // cloning
Build() // mvn clean install
Create_Image() //docker build
docker_image_push() // for pushing the image
deploying_to_k8s() // for k8s deployment
}
}
def Checkout()
{
stage('Checkout')
{
checkout scm
}
}
def Build()
{
stage('Build')
{
sh "cd ${params.Service_Name} ; mvn clean install "
}
}
def Create_Image()
{
stage('Create_Image')
{
sh "cd $WORKSPACE/${params.Service_Name} ; sudo docker build --tag=${params.Service_Name} ."
}
}
def docker_image_push()
{
stage('image pushing')
{
sh "sudo docker login -uankit1111 -pmiet@1234"
sh " sudo docker tag ${params.Service_Name} ankit1111/${params.Service_Name}:v1"
sh " sudo docker push ankit1111/${params.Service_Name}:v1"
}
}
def deploying_to_k8s() {
stage('k8s deployment') {
node ("ansible-machine")
{
sh "cd /opt ; sudo ansible-playbook devops.yaml"
}
}
}