exceljenkinsvbscript

Excel does not become visible when the VBScript is triggered via Jenkins


I have written a simple VBScript code which:

The code is as follows:

Option Explicit
Dim objExcel, objBook, objSheet, strPath
strPath = "C:\Users\user\Test.xlsx"
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.DisplayAlerts = False
Set objBook = objExcel.Workbooks.Open(strPath)
Set objSheet = objBook.Sheets("Sheet1")
objSheet.Cells(1,1) = "Time: " & time
objBook.Save
'objBook.Close
'objExcel.Quit

When I run this VBScript file(directly by double-clicking, not via Jenkins), all the 4 steps mentioned above run fine. When I run the same file via Jenkins, the following happens:

The issue is that the Excel workbook does not become visible. I have been stuck on this step for hours now. Today is the first time I am using Jenkins. Is there any Jenkins configuration that I am missing? Has anyone ever faced this issue?

I am running Windows batch command on Jenkins to achieve the same:

C:\Windows\SysWOW64\cscript.exe "C:\Users\usrnamr\TEST.vbs"

This is how my build console looks like after running the build:

Started by user username
Building in workspace C:\Program Files (x86)\Jenkins\workspace\SuiteRunner
[SuiteRunner] $ cmd /c call C:\WINDOWS\TEMP\jenkins2976471610072523635.bat

C:\Program Files (x86)\Jenkins\workspace\SuiteRunner>C:\Windows\SysWOW64\cscript.exe "C:\Users\username\TEST.vbs" 
Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.


C:\Program Files (x86)\Jenkins\workspace\SuiteRunner>exit 0 
Finished: SUCCESS

Any help/suggestion would be appreciated.


Solution

  • I took help from this answer To solve the issue, I performed these steps:

    1. Downloaded the generic war package from https://jenkins.io/download/

    enter image description here

    1. Ran the jenkins from command line using the command java -jar jenkins.war

    2. Complete the Installation(configure proxy, if any; download plugins, credentials etc) enter image description here

    3. Entered the batch command enter image description here

    4. After clicking on Build now, I was able to see the excel getting launched. enter image description here