forked from vivekkaushik1/samplejava
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
106 lines (105 loc) · 5.12 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
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
//def appName='E2E_App'
def appName='PerfApps0'
def snapName=''
//def deployName = 'TEST'
//def deployName ='PerfApps0_dep__1'
def deployName ='PerfApps0_dep__0'
def exportFormat ='json'
def configFilePath = "paymentService"
def fileNamePrefix ='exported_file_'
def fullFileName="${appName}-${deployName}-${currentBuild.number}.${exportFormat}"
def changeSetId=""
def snapshotName=""
def exporterName ='returnAllData'
// def namePath ="E2E/pipelineUpload/${currentBuild.number}"
// def namePath ='component1'
def namePath ="PerfApps0_dep__coll__comp_0/${JOB_NAME}/${currentBuild.number}"
pipeline {
agent any
stages {
stage('Clone repository') {
steps{
// checkout scm
git branch: 'master', url: 'https://github.com/iamkumaramit/samplejava.git'
}
}
stage('Validate Configurtion file'){
steps{
script{
sh "echo validating configuration file ${configFilePath}.${exportFormat}"
echo "name path ::::: ${namePath}"
changeSetId = snDevOpsConfigUpload(applicationName:"${appName}",target:'component',namePath:"${namePath}", fileName:"component1", autoCommit:'true',autoValidate:'true',dataFormat:"${exportFormat}")
// snDevOpsConfigUpload(applicationName:"${appName}",target:'deployable',namePath:"${namePath}", fileName:"deployable", autoCommit:'true',autoValidate:'true',dataFormat:"${exportFormat}",changesetNumber:"${changeSetId}", deployableName:"${deployName}")
echo "validation result $changeSetId"
}
}
}
stage("register change set to pipeline"){
steps{
script{
echo "Change set registration for ${changeSetId}"
changeSetRegResult = snDevOpsConfigRegisterChangeSet(changesetId:"${changeSetId}")
echo "change set registration set result ${changeSetRegResult}"
}
}
}
stage("Get snapshots created"){
steps{
echo "Triggering Get snapshots for applicationName:${appName},deployableName:${deployName},changeSetId:${changeSetId}"
script{
changeSetResults = snDevOpsConfigGetSnapshots(applicationName:"${appName}",deployableName:"${deployName}",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 snapshot found to proceed" ;
}
echo "Snapshot Name : ${snapshotName} "
}
}
}
stage('Publish the snapshot'){
steps{
script{
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'){
steps{
echo "Devops Change trigger change request"
snDevOpsChange()
}
}
stage('Download Snapshots from Service Now') {
steps{
script{
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"){
steps{
echo "Reading config from file name ${fullFileName}"
echo " ++++++++++++ BEGIN OF File Content ***************"
sh "cat ${fullFileName}"
echo " ++++++++++++ END OF File content ***************"
echo "deploy finished successfully."
}
}
}
}