在Jenkins上以管理员身份运行批处理文件?

时间:2022-12-20 02:17:07

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

我们在Win8 x64上使用Jenkins来构建(msbuild),包(cspack),运行(csrun)和测试(nunit)一个azure云服务项目。 Azure云服务模拟器需要以管理员身份运行,我们需要绑定到端口80/443(因此不能使用“精简”模拟器)。

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)

我们通过Jenkins运行的简单.bat文件来完成上述操作。通常没有用户登录到计算机,它启动并且Jenkin作为一项服务运行,持续监控我们的GIT仓库和电子邮件的故障。管理员手动登录机器进行维护(例如应用补丁或重启机器等)

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

我们如何配置Jenkins以管理员身份运行.bat而无需人工干预?

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.

使用桌面UI,我们可以右键单击命令提示符,以管理员身份运行,确认UAC提示,获取提升的权限提示并运行.bat文件。

3 个解决方案

#1


16  

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.

我们的解决方案是将Jenkins的服务作为单独的本地管理员用户运行。安装Jenkins之后,开始=>'services'=>滚动到Jenkins服务=>右键单击=> properties =>“登录”=>“此帐户”=>指定本地管理员帐户。

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

希望在更新的Jenkins构建中,它可以作为标准的网络服务工作,但出于某种原因,它不适用于我们的盒子。

#2


1  

One of the solution:

其中一个解决方案:

  1. Create bat file in slave.
  2. 在slave中创建bat文件。
  3. Create shortcut of the file and right click the shortcut, properties -> Advanced -> check run as administrator.
  4. 创建文件的快捷方式,右键单击快捷方式,属性 - >高级 - >选中以管理员身份运行。
  5. Control Panel -> System and Security -> Action Center -> Change User Account Control Settings and set the level to "never notify".
  6. 控制面板 - >系统和安全 - >操作中心 - >更改用户帐户控制设置并将级别设置为“从不通知”。
  7. run the file on Jenkins
  8. 在Jenkins上运行该文件

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

不知何故,该文件将在从属服务器上执行,但它在Jenkins上返回失败。

#3


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

如果您以管理员身份登录widows机器并从该用户运行slave代理,则所有内容都将在管理员用户下运行

#1


16  

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.

我们的解决方案是将Jenkins的服务作为单独的本地管理员用户运行。安装Jenkins之后,开始=>'services'=>滚动到Jenkins服务=>右键单击=> properties =>“登录”=>“此帐户”=>指定本地管理员帐户。

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

希望在更新的Jenkins构建中,它可以作为标准的网络服务工作,但出于某种原因,它不适用于我们的盒子。

#2


1  

One of the solution:

其中一个解决方案:

  1. Create bat file in slave.
  2. 在slave中创建bat文件。
  3. Create shortcut of the file and right click the shortcut, properties -> Advanced -> check run as administrator.
  4. 创建文件的快捷方式,右键单击快捷方式,属性 - >高级 - >选中以管理员身份运行。
  5. Control Panel -> System and Security -> Action Center -> Change User Account Control Settings and set the level to "never notify".
  6. 控制面板 - >系统和安全 - >操作中心 - >更改用户帐户控制设置并将级别设置为“从不通知”。
  7. run the file on Jenkins
  8. 在Jenkins上运行该文件

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

不知何故,该文件将在从属服务器上执行,但它在Jenkins上返回失败。

#3


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

如果您以管理员身份登录widows机器并从该用户运行slave代理,则所有内容都将在管理员用户下运行