forked from afonsoft/CxViewerVSIX
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathJenkinsfile
More file actions
141 lines (133 loc) · 5.36 KB
/
Jenkinsfile
File metadata and controls
141 lines (133 loc) · 5.36 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
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
#!/groovy
@Library('cx-jenkins-pipeline-kit')
import groovy.xml.DOMBuilder
import groovy.xml.XmlUtil
import javax.xml.parsers.DocumentBuilderFactory
import org.w3c.dom.Document
def ipAddress
def vmName = "Plugin-VisualStudio-" + UUID.randomUUID().toString()
def msbuildLocationVS2019 = "\"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Professional\\MSBuild\\Current\\Bin\\MSBuild.exe\""
def msbuildLocationVS2022 = "\"C:\\Program Files\\Microsoft Visual Studio\\2022\\Professional\\MSBuild\\Current\\Bin\\MSBuild.exe\""
def versionOfVS2022
def versionOfVS2019
def decommissionPeriod = "3 hour"
pipeline {
parameters {
choice(name: "templateName", choices: ["VisualStudio2019-Template","VisualStudio2022-Template"], description: "Template name, if not specified then \"VisualStudio2019-Template\" template will be chosen")
booleanParam(name: 'doNotDeleteVM', defaultValue: false, description: 'If selected, VM will not be deleted after process finished')
gitParameter branchFilter: 'origin/(.*)', defaultValue: 'master', name: 'branch', type: 'PT_BRANCH'
}
agent { node { label 'install01' } }
stages {
stage('Checkout') {
steps {
checkout([$class: 'GitSCM',
branches: [[name: "${branch}"]],
userRemoteConfigs: [[url: 'https://github.com/checkmarx-ltd/VisualStudio.git']]])
}
}
stage('Extract Version') {
steps {
script {
if(templateName == "VisualStudio2019-Template")
{
def vs2019ManifestPath = 'CxViewerVSIX/source.extension.vsixmanifest'
// Extract versions using a helper function
versionOfVS2019 = extractVersionUsingDOMBuilder(vs2019ManifestPath)
echo "VS2019 version: ${versionOfVS2019}"
}
else
{
def vs2022ManifestPath = 'CxViewer2022/source.extension.vsixmanifest'
// Extract versions using a helper function
versionOfVS2022 = extractVersionUsingDOMBuilder(vs2022ManifestPath)
echo "VS2022 version: ${versionOfVS2022}"
}
}
}
}
stage('Create VM') {
steps {
script {
kit.Create_Vm_Terraform(vmName, templateName, "18000", "8", "VMWARE", decommissionPeriod, "Auto", "Plugins-Developers")
ipAddress = kit.getIpAddress(vmName, "VMWARE")
kit.Create_Jenkins_Slave_On_Master_cx_operation(vmName)
kit.Start_Jenkins_Slave_On_Windows_Pstools_cx_operation(ipAddress, vmName)
}
}
}
stage('Build and Pack') {
agent { node { label vmName } }
steps {
script {
if(templateName == "VisualStudio2019-Template")
{
bat "${msbuildLocationVS2019} ${WORKSPACE}\\ci.msbuild /t:CI /p:VisualStudioVersion=\"16.0\" /p:DeployExtension=false"
}
else {
bat "${msbuildLocationVS2022} ${WORKSPACE}\\ci.msbuild2022 /t:CI /p:VisualStudioVersion=\"17.0\" /p:DeployExtension=false"
}
}
}
}
stage('Upload To Artifactory') {
agent { node { label vmName } }
steps {
script {
if(templateName == "VisualStudio2019-Template")
{
kit.Upload_To_Artifactory("${WORKSPACE}\\Artifacts\\CxViewerVSIX-2019.vsix", "plugins-release-local/com/checkmarx/visual-studio/${versionOfVS2019}/")
}
else
{
kit.Upload_To_Artifactory("${WORKSPACE}\\Artifacts\\CxViewerVSIX-2022.vsix", "plugins-release-local/com/checkmarx/visual-studio/${versionOfVS2022}/")
}
}
}
}
}
post {
always {
script {
//logstashSend failBuild: false, maxLines: 1000 - commented code due to job failed because of logstashSend plugin not found
if (ipAddress != null) {
try {
if (doNotDeleteVM == 'true') {
kit.Info_Msg("Not deleting VM since user chose to keep it")
} else {
deleteVm("VMWARE", ipAddress, vmName)
}
} catch (Exception e) {
kit.Warning_Msg("Failed to delete vm. Exception:\n" + e.toString())
currentBuild.result = 'UNSTABLE'
}
}
}
}
cleanup {
cleanWs()
}
}
}
def extractVersionUsingDOMBuilder(manifestPath) {
def manifestContent = readFile(manifestPath)
manifestContent = manifestContent.replaceFirst(/^\xEF\xBB\xBF/, '').trim()
def version = ''
try {
// Create DocumentBuilderFactory and parse the XML content
def factory = DocumentBuilderFactory.newInstance()
def builder = factory.newDocumentBuilder()
def inputStream = new ByteArrayInputStream(manifestContent.getBytes("UTF-8"))
// Parse the input stream into a Document
Document document = builder.parse(inputStream)
// Use DOM to extract the Version attribute
def node = document.getElementsByTagName("Identity").item(0)
version = node?.getAttribute("Version")
if (!version) {
error "Version attribute not found in ${manifestPath}"
}
return version
} catch (Exception e) {
error "Failed to parse XML using DOMBuilder for ${manifestPath}: ${e.message}"
}
}