Run Jenkins job (on Windows) as non-admin

by Pporfiry   Last Updated September 11, 2019 19:01 PM - source

I am trying to run a Windows Jenkins job using the 'Execute Windows batch command". The job is to run a Python script that uses subprocess to repeatedly invoke a windows console executable. The exe is required to not run as admin. It looks like the default config for the Jenkins slave agent is to run the Windows batch command as admin. The issue is not running the python script, it runs as expected.

I have come across the workaround of using 'runas /trustlevel:0x20000 "cmd /c myscript.py"' in the Jenkins job but that doesn't work as desired because:

  1. The 'runas' spawns another process and returns right away, with the result that the Jenkins job exits 'successfully' and immediately, regardless of how long the script ends up running (it can run awhile). The script will also output progress to stdout that is lost when 'runas' is used unless I redirect output. Ideally would like to see stdout progress in the 'Console Output'
  2. The script will produce an output file that I want to keep as an artifact. But since the job finishes as soon as 'runas' executes, Jenkins won't see the artifact before exiting the job.

Have also tried the 'Authorize Project' plugin and configured the job to run 'as user who triggered job', but job still appears to run as admin.

Is there a Jenkins slave configuration or acct setup to get jobs to run as non-admin? The fallback is to update the Python script to lower privileges when creating the subprocess to run the Windows executable. I am assuming the best way to do this is to use the Win32 api package and use something like CreateRestrictedToken and CreateProcessAsUser approach which I have seen snippets of.

Thanks in advance and apologies if I violate any protocols as this is my first post/question.

Tags : windows jenkins


Related Questions


Windows Remote Registry/DCOM access without SMBv1

Updated November 02, 2017 10:01 AM

windows 10 as a build agent - preventing disk changes

Updated December 07, 2017 19:01 PM

installing jenkins on windows server

Updated March 01, 2018 18:01 PM

Need help upgrading Tomcat 7 on Windows

Updated July 09, 2018 18:01 PM