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

15,614

Solution 1

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".

Solution 2

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.

Share:
15,614
gpalex
Author by

gpalex

Updated on June 17, 2022

Comments

  • gpalex
    gpalex almost 2 years

    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