【发布时间】:2018-11-26 05:28:55
【问题描述】:
我需要帮助来弄清楚为什么 Git 存储库命令在 Windows Server 2016 任务调度程序中的脚本中运行时没有执行。当我在命令控制台中执行它们时,一切正常。
在 Windows Server 2016 任务计划程序中,我的“启动程序”操作为:C:\Apps\repo.scripts\UpdateMyRepo.bat
UpdateMyRepo.bat cmd 代码是:
SET HOME=C:\Users\Repo
REM change to MyRepo git working repository
C:
cd \MyRepo
REM execute my script bash script to update my repository
C:\Apps\Git\bin\bash.exe --login -i -c "/c/Apps/repo.scripts/UpdateMyRepo.sh"
UpdateMyRepo.sh bash 代码是
#!/c/Apps/Git/bin/bash.exe -x
export HOME=/c/Users/Repo
cd /c/MyRepo
# write a log entry so we know we are in the repository folder
ls -al > /c/Apps/repo.scripts/myrepofolder.log
# write the git --version to a log file so we know git is working
/c/Apps/Git/bin/git.exe --version > /c/Apps/repo.scripts/version.log
# write the git status to a log file so we know git repository commands work
/c/Apps/Git/bin/git.exe status > /c/Apps/repo.scripts/status.log
# write a done log entry and quit the bash shell
echo done > /c/Apps/repo.scripts/done.log
exit
在 Windows 2016 任务计划程序除了 git status 命令一切正常。 git status 写入一个空的空白 status.log 文件。实际上,似乎任何其他命令,如 git add、git commit、git push 等,都对存储库产生空白输出。
如果我以 Repo 用户身份登录并在 Windows 文件资源管理器中双击 C:\Apps\repo.scripts\UpdateMyRepo.bat 或在控制台中运行时手动执行命令,则一切正常,并且存储库 git 状态将写入 status.log。从任务计划程序手动或触发执行任务时,我得到“空”结果。
请帮我弄清楚如何在 Windows Server 2016 任务调度程序中运行 git 存储库命令。我已经尝试了太多的命令、脚本和权限变体,无法在此处列出每一个。
平台详情: Windows Server 2016 Standard,所有当前更新 Git 便携式 64 位,2.17.1.windows.2 存储库文件存储在操作系统和任务计划程序的本地硬盘中,而不是网络共享中
更新:当我在 WS2016 任务计划程序中运行 Git 存储库任务并弄清楚如何记录一些输出时,我收到以下错误:
fatal: this operation must be run in a work tree
存储库文件夹不是“裸”存储库。所以我怀疑 WS2016 任务计划程序正在应用不适用于任务中分配的用户帐户的其他权限限制。如果我尝试在管理控制台而不是普通用户控制台中运行任务,我会收到同样的错误。
【问题讨论】:
标签: bash git taskscheduler windows-server-2016