11#! /groovy
22@Library (' cx-jenkins-pipeline-kit' )
3+ import groovy.xml.DOMBuilder
4+ import groovy.xml.XmlUtil
5+ import javax.xml.parsers.DocumentBuilderFactory
6+ import org.w3c.dom.Document
37
48def ipAddress
59def vmName = " Plugin-VisualStudio-" + UUID . randomUUID(). toString()
6- def msbuildLocationVS2019 = " \" C:\\ Program Files (x86)\\ Microsoft Visual Studio\\ 2019\\ Enterprise \\ MSBuild\\ Current\\ Bin\\ MSBuild.exe\" "
10+ def msbuildLocationVS2019 = " \" C:\\ Program Files (x86)\\ Microsoft Visual Studio\\ 2019\\ Professional \\ MSBuild\\ Current\\ Bin\\ MSBuild.exe\" "
711def msbuildLocationVS2022 = " \" C:\\ Program Files\\ Microsoft Visual Studio\\ 2022\\ Professional\\ MSBuild\\ Current\\ Bin\\ MSBuild.exe\" "
12+ def versionOfVS2022
13+ def versionOfVS2019
14+ def decommissionPeriod = " 3 hour"
815
916pipeline {
1017 parameters {
11- string(name : " decommissionPeriod" , defaultValue : " 3 hour" , description : " Decommission period" )
1218 choice(name : " templateName" , choices : [" VisualStudio2019-Template" ," VisualStudio2022-Template" ], description : " Template name, if not specified then \" VisualStudio2019-Template\" template will be chosen" )
1319 booleanParam(name : ' doNotDeleteVM' , defaultValue : false , description : ' If selected, VM will not be deleted after process finished' )
1420 gitParameter branchFilter : ' origin/(.*)' , defaultValue : ' master' , name : ' branch' , type : ' PT_BRANCH'
1521 }
1622 agent { node { label ' install01' } }
1723 stages {
24+ stage(' Extract Version' ) {
25+ steps {
26+ script {
27+ if (templateName == " VisualStudio2019-Template" )
28+ {
29+ def vs2019ManifestPath = ' CxViewerVSIX/source.extension.vsixmanifest'
30+ // Extract versions using a helper function
31+ versionOfVS2019 = extractVersionUsingDOMBuilder(vs2019ManifestPath)
32+ echo " VS2019 version: ${ versionOfVS2019} "
33+ }
34+ else
35+ {
36+ def vs2022ManifestPath = ' CxViewer2022/source.extension.vsixmanifest'
37+ // Extract versions using a helper function
38+ versionOfVS2022 = extractVersionUsingDOMBuilder(vs2022ManifestPath)
39+ echo " VS2022 version: ${ versionOfVS2022} "
40+ }
41+ }
42+ }
43+ }
1844 stage(' Create VM' ) {
1945 steps {
2046 script {
2147 kit.Create_Vm_Terraform (vmName, templateName, " 18000" , " 8" , " VMWARE" , decommissionPeriod, " Auto" , " Plugins-Developers" )
2248 ipAddress = kit. getIpAddress(vmName, " VMWARE" )
23- kit.Create_Jenkins_Slave_On_Master (vmName)
24- kit.Start_Jenkins_Slave_On_Windows_Pstools (ipAddress, vmName)
49+ kit.Create_Jenkins_Slave_On_Master_cx_operation (vmName)
50+ kit.Start_Jenkins_Slave_On_Windows_Pstools_cx_operation (ipAddress, vmName)
2551 }
2652 }
2753 }
28-
54+
2955 stage(' Build and Pack' ) {
3056 agent { node { label vmName } }
3157 steps {
@@ -41,19 +67,17 @@ pipeline {
4167 }
4268 }
4369
44- stage(' Upload To Artifactory' ) {
70+ stage(' Upload To Artifactory' ) {
4571 agent { node { label vmName } }
4672 steps {
4773 script {
4874 if (templateName == " VisualStudio2019-Template" )
4975 {
50- fileOperations([folderRenameOperation(source : " ${ WORKSPACE} \\ Artifacts\\ CxViewerVSIX-2019.vsix" , destination : " ${ WORKSPACE} \\ Artifacts\\ CxViewerVSIX-9.00.19.vsix" )])
51- kit.Upload_To_Artifactory (" ${ WORKSPACE} \\ Artifacts\\ CxViewerVSIX-9.00.19.vsix" , " plugins-release-local/com/checkmarx/visual-studio/" )
76+ kit.Upload_To_Artifactory (" ${ WORKSPACE} \\ Artifacts\\ CxViewerVSIX-2019.vsix" , " plugins-release-local/com/checkmarx/visual-studio/${ versionOfVS2019} /" )
5277 }
5378 else
5479 {
55- fileOperations([folderRenameOperation(source : " ${ WORKSPACE} \\ Artifacts\\ CxViewerVSIX-2022.vsix" , destination : " ${ WORKSPACE} \\ Artifacts\\ CxViewerVSIX-9.00.19.vsix" )])
56- kit.Upload_To_Artifactory (" ${ WORKSPACE} \\ Artifacts\\ CxViewerVSIX-9.00.19.vsix" , " plugins-release-local/com/checkmarx/visual-studio/" )
80+ kit.Upload_To_Artifactory (" ${ WORKSPACE} \\ Artifacts\\ CxViewerVSIX-2022.vsix" , " plugins-release-local/com/checkmarx/visual-studio/${ versionOfVS2022} /" )
5781 }
5882 }
5983 }
@@ -83,3 +107,28 @@ pipeline {
83107 }
84108 }
85109}
110+ def extractVersionUsingDOMBuilder (manifestPath ) {
111+ def manifestContent = readFile(manifestPath)
112+ manifestContent = manifestContent. replaceFirst(/ ^\x EF\x BB\x BF/ , ' ' ). trim()
113+
114+ def version = ' '
115+ try {
116+ // Create DocumentBuilderFactory and parse the XML content
117+ def factory = DocumentBuilderFactory . newInstance()
118+ def builder = factory. newDocumentBuilder()
119+ def inputStream = new ByteArrayInputStream (manifestContent. getBytes(" UTF-8" ))
120+
121+ // Parse the input stream into a Document
122+ Document document = builder. parse(inputStream)
123+
124+ // Use DOM to extract the Version attribute
125+ def node = document. getElementsByTagName(" Identity" ). item(0 )
126+ version = node?. getAttribute(" Version" )
127+ if (! version) {
128+ error " Version attribute not found in ${ manifestPath} "
129+ }
130+ return version
131+ } catch (Exception e) {
132+ error " Failed to parse XML using DOMBuilder for ${ manifestPath} : ${ e.message} "
133+ }
134+ }
0 commit comments