16

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.

4 Answers 4

24

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.

2
  • Cannot find the option, is that so in Windows 10 ?
    – c4sh
    Mar 6, 2019 at 15:19
  • It works like a charm. I haved the same issue with my jenkins instance executing a bat command, thanks a lot dude Nov 13, 2019 at 15:30
5

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.

3
  • for interest sake, if your file was update.bat, the shortcut would be update.bat.lnk, which you can then refer to in Jenkins. May 24, 2017 at 5:05
  • jenkins fails to detect the .lnk as a .bat ... how to solve that?
    – c4sh
    Mar 5, 2019 at 16:38
  • 1
    "Shomehow the file will be executed on slave server but it return failure on Jenkins" Did you guys find a way to know if the file executed went fine or not?
    – c4sh
    Mar 6, 2019 at 14:27
2

This is My situation:

I need to use admin privileged console to run pywinauto script (written in python) to automate some app which requires admin privileged.

What I had tried:

  1. In my experience, install Windows Jenkins slave as a service creating more issue to take care with, so I don't go this route.
  2. To create a new process and it will open a new admin privileged shell and run command on it. But, in this way, Jenkins will not show its output, say in Blue Ocean.

What worked for me:

  1. Just manually open an admin privileged console to start the your_window_node.jnlp file and then this Jenkins slave will have admin privileged.
0
0

If you'll log to the widows machine as an administrator and run the slave agent from this user, everything will be running under the administrator user

4
  • How do we run the slave agent? New to the setup but we installed it as a service that becomes alive anytime the build server machine comes online. Thanks! Dec 11, 2014 at 0:21
  • I don't think it is matter, which user is logged in to the windows machine? I think that if you'll log in as Administrator user - you'll be fine.
    – kazerm
    Dec 11, 2014 at 0:24
  • 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 logs into the machine just to maintenance (eg. apply patches or reboot machine etc) Dec 11, 2014 at 0:26
  • Try this: stackoverflow.com/questions/22888712/…
    – kazerm
    Dec 11, 2014 at 0:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.