Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run batch file as administrator on Jenkins?

We're using Jenkins on Win8 x64 to build (msbuild), package (cspack), run (csrun) and test (nunit) an azure cloud services project. The Azure cloud service emulators need to run as administrator plus we need to bind to ports 80/443 (so can't use "lite" emulators).

We're doing the above via a simple .bat file that Jenkins runs. Typically no user logs into the machine, it boots up and Jenkin's runs as a service that keeps monitoring our GIT repo and emails on failures. An admin manually logs into the machine just for maintenance (eg. apply patches or reboot machine etc)

How do we configure Jenkins to run that .bat as administrator without human interaction?

With a desktop UI we can right click a command prompt, run as admin, acknowledge the UAC prompt, get the elevated privilege prompt and run the .bat file.

like image 584
DeepSpace101 Avatar asked Dec 11 '14 00:12

DeepSpace101


People also ask

How do you run a batch file in Jenkins?

Add the batch command as run. Click on Apply and save the configuration then, you will redirect to the Project Workspace. Click on the Build Now, it will execute the given batch command that executes the run. bat file. You can see the console results on the Console Output.


2 Answers

Our solution was to run the Jenkins' service as a separate local admin user. After installing Jenkins, Start => 'services' => Scroll to the Jenkins service => right click => properties => "log on" => "this account" => specify a local admin account.

Hopefully in newer Jenkins' builds it can work as the standard NETWORK SERVICE but for some reason it didn't with our box.

like image 50
DeepSpace101 Avatar answered Oct 08 '22 19:10

DeepSpace101


One of the solution:

  1. Create bat file in slave.
  2. Create shortcut of the file and right click the shortcut, properties -> Advanced -> check run as administrator.
  3. Control Panel -> System and Security -> Action Center -> Change User Account Control Settings and set the level to "never notify".
  4. run the file on Jenkins

Somehow the file will be executed on slave server but it return failure on Jenkins.

like image 36
Roy Pun Avatar answered Oct 08 '22 19:10

Roy Pun