-
Notifications
You must be signed in to change notification settings - Fork 2
/
Jenkinsfile-local
147 lines (102 loc) · 5.95 KB
/
Jenkinsfile-local
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
node {
def app
def appName='App1'
def snapName=''
def deployName = 'PROD-US'
// Json Example
def configFilePath = "paymentService"
def exportFormat ='json'
// Yaml Example
// def exportFormat ='yml'
// def configFilePath = "k8s/demo-training-studio-dev"
def fileNamePrefix ='exported_file_'
def fullFileName="${fileNamePrefix}-${appName}-${deployName}-${currentBuild.number}.${exportFormat}"
def changeSetId=""
def snapshotName=""
def exporterName ='Santosh-yaml'
def dockerImageName = "santoshnrao/demo-training-studio"
def dockerImageTag=""
stage('Clone repository') {
checkout scm
}
stage('Build image') {
snDevOpsStep()
// app = docker.build("santoshnrao/demo-training-studio")
}
stage('Test image') {
sh 'echo "Tests passed"'
}
stage('Push image') {
sh 'ls -a'
dockerImageTag = env.BUILD_NUMBER
dockerImageNameTag = "${dockerImageName}" + ":" + "${dockerImageTag}"
// docker.withRegistry('https://registry.hub.docker.com', 'santoshnrao-dockerhub') {
// app.push("${dockerImageTag}")
// app.push("latest")
// }
snDevopsArtifactPayload = '{"artifacts": [{"name": "' + dockerImageName + '", "version": "' + "${dockerImageTag}" + '", "semanticVersion": "' + "0.1.${dockerImageTag}"+ '","repositoryName": "' + dockerImageName+ '"}, ],"stageName":"Build image","branchName": "main"}' ;
echo " docker Image artifacat ${dockerImageNameTag} "
echo "snDevopsArtifactPayload ${snDevopsArtifactPayload} "
snDevOpsArtifact(artifactsPayload:snDevopsArtifactPayload)
}
stage('Validate Configurtion file'){
sh "echo validating configuration file ${configFilePath}.${exportFormat}"
changeSetId = snDevOpsConfigUpload(applicationName:"${appName}",target:'component',namePath:'paymentservice.v1.1', fileName:"${configFilePath}", autoCommit:'true',autoValidate:'true',dataFormat:"${exportFormat}")
echo "validation result $changeSetId"
}
stage("register change set to pipeline"){
echo "Change set registration for ${changeSetId}"
changeSetRegResult = snDevOpsConfigRegisterChangeSet(changesetId:"${changeSetId}")
echo "change set registration set result ${changeSetRegResult}"
}
stage("Get snapshots created"){
echo "Triggering Get snapshots for applicationName:${appName},deployableName:${deployName},changeSetId:${changeSetId}"
changeSetResults = snDevOpsConfigGetSnapshots(applicationName:"${appName}",deployableName:"${deployName}",changeSetId:"${changeSetId}")
echo "ChangeSet Result : ${changeSetResults}"
def changeSetResultsObject = readJSON text: changeSetResults
// def changeSetResultsObject = jsonSlurper.parseText("${changeSetResults}")
changeSetResultsObject.each {
if(it.validation == "passed"){
echo "validation passed for snapshot : ${it.name}"
snapshotName = it.name
}else{
echo "Snapshot failed to get validated : ${it.name}" ;
assert it.validation == "passed"
}
}
if (!snapshotName?.trim()){
error "No snapshot found to proceed" ;
}
echo "Snapshot Name : ${snapshotName} "
}
stage('Publish the snapshot'){
echo "Step to publish snapshot applicationName:${appName},deployableName:${deployName} snapshotName:${snapshotName}"
publishSnapshotResults = snDevOpsConfigPublish(applicationName:"${appName}",deployableName:"${deployName}",snapshotName: "${snapshotName}")
echo " Publish result for applicationName:${appName},deployableName:${deployName} snapshotName:${snapshotName} is ${publishSnapshotResults} "
}
stage('Deploy to the System'){
echo "Devops Change trigger change request"
snDevOpsChange()
}
stage('Download Snapshots from Service Now') {
echo "Exporting for App: ${appName} Deployable; ${deployName} Exporter name ${exporterName} "
echo "Configfile exporter file name ${fullFileName}"
sh 'echo "<<<<<<<<<export file is starting >>>>>>>>"'
response = snDevOpsConfigExport(applicationName: "${appName}", snapshotName: "${snapName}", deployableName: "${deployName}",exporterFormat: "${exportFormat}", fileName:"${fullFileName}",exporterName: "${exporterName}")
echo " RESPONSE FROM EXPORT : ${response}"
}
stage("Deploying to PROD-US"){
echo "Reading config from file name ${fullFileName}"
echo " ++++++++++++ BEGIN OF File Content ***************"
sh "cat ${fullFileName}"
echo " ++++++++++++ END OF File content ***************"
echo "deploy finished successfully."
// sh 'kubectl version'
// sh 'kubectl config view'
echo "********************** BEGIN Deployment ****************"
echo "Applying docker image ${dockerImageNameTag}"
sh "helm upgrade demo-training-studio k8s/demo-training-studio/ -i --set image.tag=${dockerImageTag} --set image.repository=${dockerImageName}"
// sh "kubectl apply -f k8s/demo-training-studio-dev.yml --image ${dockerImageName}"
echo "********************** END Deployment ****************"
}
}