最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

windows - Bat file runs locally from cmd, but loops when ran using Jenkins - Stack Overflow

programmeradmin2浏览0评论

I created the following .bat file in order to shutdown onedrive service:

whoami
"C:\Program Files\Microsoft OneDrive\OneDrive.exe" /shutdown

If I double-click on the .bat icon file, this works. Also, this works when I run a command line shell and type "C:\Users\john\Desktop\onedrive-shutdown.bat".

Now, I am running a Jenkins service on the same windows server which is connected as john (logon properties) and I created a project which consists of the following build step:

Unfortunately, the /shutdown process hangs up/loops since I am getting the following output:

whoami
john
"C:\Program Files\Microsoft OneDrive\OneDrive.exe" /shutdown

(and ... icon. Also, OneDrive won't be shutdown).

What am I missing?

Note that:

  • Jenkins service logon properties is set as: john
  • I tried psexec64 -i 1 -u john -p PASSWORD "C:\Program Files\Microsoft OneDrive\OneDrive.exe" /shutdown, but this won't work (same results).
  • I cannot use runas since user john user has got a password.
  • Any other .bat file, such as echo "Hello World" works fine.

I created the following .bat file in order to shutdown onedrive service:

whoami
"C:\Program Files\Microsoft OneDrive\OneDrive.exe" /shutdown

If I double-click on the .bat icon file, this works. Also, this works when I run a command line shell and type "C:\Users\john\Desktop\onedrive-shutdown.bat".

Now, I am running a Jenkins service on the same windows server which is connected as john (logon properties) and I created a project which consists of the following build step:

Unfortunately, the /shutdown process hangs up/loops since I am getting the following output:

whoami
john
"C:\Program Files\Microsoft OneDrive\OneDrive.exe" /shutdown

(and ... icon. Also, OneDrive won't be shutdown).

What am I missing?

Note that:

  • Jenkins service logon properties is set as: john
  • I tried psexec64 -i 1 -u john -p PASSWORD "C:\Program Files\Microsoft OneDrive\OneDrive.exe" /shutdown, but this won't work (same results).
  • I cannot use runas since user john user has got a password.
  • Any other .bat file, such as echo "Hello World" works fine.
Share Improve this question edited Feb 5 at 9:29 tail asked Feb 4 at 15:30 tailtail 4313 silver badges22 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

The issue arises because Jenkins runs as a system process (0), while OneDrive requires an interactive user session (1) to function correctly. To resolve this, I created two scheduled tasks to execute the batch files in the correct user contex.

Here's how I solved it:

  1. Created two batch files so that execute the following commands: "C:\Program Files\Microsoft OneDrive\OneDrive.exe" /shutdown and "C:\Program Files\Microsoft OneDrive\OneDrive.exe" /background.
  2. Created a task for /shutdown command: schtasks /create /tn "OneDriveShutdownTask" /tr "C:\Users\john\Desktop\onedrive-shutdown.bat" /sc onstart /ru john /rl HIGHEST
  3. Created a task for /background command: schtasks /create /tn "OneDriveBackgroundTask" /tr "C:\Users\john\Desktop\onedrive-background.bat" /sc onstart /ru john /rl LIMITED (note LIMITED here, since OneDrive can't be ran in HIGHEST mode).
  4. Launch schtasks /run /tn "OnedriveShutdownTask" or schtasks /run /tn "OnedriveBackgroundTask" either using Windows CMD or using Jenkins.
发布评论

评论列表(0)

  1. 暂无评论