-
Notifications
You must be signed in to change notification settings - Fork 1
/
DemoJenkinsfile
111 lines (83 loc) · 4.21 KB
/
DemoJenkinsfile
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
def buildNumber = "${env.BUILD_NUMBER}"
node {
def appName='devops-demo-web-app'
def snapName=''
def deployableName = 'PROD-US'
def setYamlUpload = true
// Json Example
def configFilePath = "paymentService"
def exportFormat ='json'
// Yaml Example
if(setYamlUpload){
exportFormat ='yaml'
configFilePath = "k8s/helm/values"
}
def fileNamePrefix ='exported_file_'
def fullFileName="${fileNamePrefix}-${deployableName}-${currentBuild.number}.${exportFormat}"
def changeSetId=""
def componentName="devops-config-demo-web-app-v1.1"
def collectionName="release-1.0"
def snapshotName=""
def exporterName ='k8s-exporter'
def exporterArgs = '{"component": "' + componentName + '", "collection": "' + collectionName + '", "deployable": "' + deployableName + '"}'
def dockerImageName = "sannrao/web-api"
def dockerImageTag=""
// agent any
// tools {
// maven 'maven'
// }
stage("Checkout and build"){
// snDevOpsStep()
checkout scm
// sh 'mvn clean install'
}
stage("Tests") {
// agent any
// sh 'mvn clean verify'
}
stage('Upload Configuration Files'){
sh "echo validating configuration file ${configFilePath}.${exportFormat}"
changeSetId = snDevOpsConfigUpload(applicationName:"${appName}",target:'component',namePath:"${componentName}", fileName:"${configFilePath}", autoCommit:'true',autoValidate:'true',dataFormat:"${exportFormat}")
echo "validation result $changeSetId"
echo "Change set registration for ${changeSetId}"
changeSetRegResult = snDevOpsConfigRegisterChangeSet(changesetId:"${changeSetId}")
echo "change set registration set result ${changeSetRegResult}"
}
stage("Get snapshot status"){
echo "Triggering Get snapshots for applicationName:${appName},deployableName:${deployableName},changeSetId:${changeSetId}"
changeSetResults = snDevOpsConfigGetSnapshots(applicationName:"${appName}",deployableName:"${deployableName}",changeSetId:"${changeSetId}")
echo "ChangeSet Result : ${changeSetResults}"
def changeSetResultsObject = readJSON text: 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 valid snapshot found to proceed" ;
}
echo "Snapshot Name : ${snapshotName} "
}
stage('Publish the snapshot'){
echo "Step to publish snapshot applicationName:${appName},deployableName:${deployableName} snapshotName:${snapshotName}"
publishSnapshotResults = snDevOpsConfigPublish(applicationName:"${appName}",deployableName:"${deployableName}",snapshotName: "${snapshotName}")
echo " Publish result for applicationName:${appName},deployableName:${deployableName} snapshotName:${snapshotName} is ${publishSnapshotResults} "
}
stage('Export Snapshots from Service Now') {
echo "Devops Change trigger change request"
snDevOpsChange()
echo "Exporting for App: ${appName} Deployable; ${deployableName} Exporter name ${exporterName} "
echo "Configfile exporter file name ${fullFileName}"
sh 'echo "<<<<<<<<<export file is starting >>>>>>>>"'
response = snDevOpsConfigExport(applicationName: "${appName}", snapshotName: "${snapName}", deployableName: "${deployableName}",exporterFormat: "${exportFormat}", fileName:"${fullFileName}", exporterName: "${exporterName}", exporterArgs: "${exporterArgs}")
echo " RESPONSE FROM EXPORT : ${response}"
}
stage('Deploy'){
snDevOpsChange()
echo "Started Deploying"
}
}