gpalex
gpalex

Reputation: 852

Jenkins won't execute correctly a command from a .bat

I have set up Jenkins so that it builds my project, runs some tests and then creates an HTML page containing a report.

I made a .bat file to open the html report in my browser. There is just one line in that .bat file :

"E:\user\Visual Studio 2010\JenkinsWorkspace\JobTest\index.html"

When I run that .bat in a prompt myself, the page index.html is open (so it works).

But the problem is that when I set up a Jenkins' job to run that .bat, nothing happens. The job gets stuck after calling the .bat and never finishes.

Any idea why?

Note: I have other .bat (that do not open html pages) that are successfully executed by Jenkins.

EDIT: here is the errors I get in the prompt log from Jenkins's menu :

C:\Program Files\Jenkins\jobs\JobTest2_enUnSeulScript\workspace>echo " Opening html page" " >> Opening html page"

C:\Program Files\Jenkins\jobs\JobTest2_enUnSeulScript\workspace>"C:\Program Files\Google\Chrome\Application\chrome.exe" "E:\user\Visual Studio 2010\JenkinsWorkspace\JobTest\testResults.14h05m15s65ms.11.04.2013.trx.htm" [688:3900:0411/140520:ERROR:gpu_info_collector_win.cc(96)] Can't retrieve a valid WinSAT assessment.
[688:3900:0411/140520:ERROR:process_singleton_win.cc(540)] Lock file can not be created! Error code: 32
[688:3900:0411/140520:ERROR:chrome_browser_main.cc(1157)] Failed to create a ProcessSingleton for your profile directory. This means that running multiple instances would start multiple browser processes rather than opening a new window in the existing process. Aborting now to avoid profile corruption.
Build step 'Exécuter une ligne de commande batch Windows' marked build as failure [htmlpublisher]
Archiving HTML reports... [htmlpublisher] Archiving at PROJECT level E:\user\Visual Studio 2010\JenkinsWorkspace\JobTest to C:\Program Files\Jenkins\jobs\JobTest2_enUnSeulScript\htmlreports\HTML_Tests_Report Finished: FAILURE

Upvotes: 2

Views: 17184

Answers (3)

Slav
Slav

Reputation: 27485

I know this is late, but I just answered another question on how to open an .exe (or .bat) from Jenkins's service on Windows

Open Excel on Jenkins CI

The issue is that while your command actually works, it does that in Session 0 (which is the session of Local System user that launched your Jenkins service), which you cannot see while being logged in through your own user account, most likely in Session 1.

Hope this helps

Upvotes: 0

Robert Greathouse
Robert Greathouse

Reputation: 1034

If you are running Jenkins as a Window's service, you will probably need to enable the service to interact with the desktop. Do the following:

  1. Open the Services module
  2. Right-click on Jenkins and select "Properties"
  3. On the "Log On" tab, run as "Local System account" and select the "Allow service to interact with desktop" checkbox

-- OR --

You can run Jenkins via the command-line. Ie: "java -jar jenkins.war".

Upvotes: 6

jwernerny
jwernerny

Reputation: 7048

I am guessing that your Jenkins install is running as a Windows Service. When Jenkins is run as a service on a Windows machine it runs under the System account, not a user account. The System account usually does not have the same settings as a user account.

You might want to try starting a CMD shell as the System Account. (The answers to this question should help you with that: How Do You Run CMD under System Account.) From there, try running the batch file and see what happens. You may find that you need to setup somethings like the PATH before it works.

Upvotes: 1

Related Questions