Run batch file as administrator in Jenkins?

We use Jenkins on Win8 x64 to build (msbuild), package (cspack), run (csrun) and test (nunit) the cloud services project. Azure cloud service emulators must run as administrators, plus we need to bind to ports 80/443 (therefore, they cannot use lite emulators).

We do this through a simple .bat file that runs Jenkins. Typically, no user logs in, they log in, and Jenkin acts as a service that monitors our GIT repositories and error messages. The administrator manually logs on to the system for maintenance only (for example, applying fixes or restarting the computer, etc.)

How to configure Jenkins to run this .bat as an administrator without human interaction?

With the desktop user interface, we can right-click on the command line, run as admin, confirm the UAC prompt, receive the prompt with elevated privileges and run the .bat file.

+6
source share
3 answers

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

I hope that in the new Jenkins designs it can work as a standard NETWORK SERVICE service, but for some reason this is not with our box.

+12
source

One solution:

  • Create a bat file in the slave.
  • Create a file shortcut and right-click the shortcut, properties β†’ Advanced β†’ check execution as administrator.
  • Control Panel β†’ System and Security β†’ Action Center β†’ Change the settings for managing user accounts and set β€œnever notify”.
  • run the file on Jenkins

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

+1
source

If you log in to the widow system as an administrator and run the slave agent from this user, everything will work under the administrator user.

0
source

Source: https://habr.com/ru/post/979431/


All Articles