简体   繁体   English

在Windows .bat文件中运行“ composer update”

[英]Running “composer update” within a Windows .bat file

I've recently updated my app to use composer for all its dependencies. 我最近更新了我的应用程序,使其所有依赖项都使用composer。 As part of this, I've updated my deploy script - a combo of Grunt tasks and a batch file - to include a "composer update" after doing a "git pull". 作为此过程的一部分,我已经更新了我的部署脚本-Grunt任务和批处理文件的组合-在执行“ git pull”之后包括“ composer update”。

However, I'm finding that although the composer update runs successfully, none of the commands in the rest of the batch file after that line run. 但是,我发现尽管composer更新成功运行,但是该行之后其余批处理文件中的任何命令都没有运行。 If I take the "composer update" line out, everything else runs fine (but of course I risk having out of date/missing dependencies). 如果我删除“ composer update”行,则其他所有内容都可以正常运行(但是,我当然会冒过时/缺少依赖项的风险)。

edit: Full .bat file. 编辑:完整的.bat文件。 Without the composer update line, it runs entirely - with it, it skips out to the next part of the deploy process. 如果没有composer更新行,它将完全运行-有了它,它将跳到部署过程的下一部分。

This creates a new date-stamped folder in \\versions\\, updates the repository & updates composer dependencies in the main repo folder, does a git checkout-index into the new version folder, uses xcopy to copy the Vendor folder with composer dependencies to the new version (because it's ignored by git) and then updates some symlinks, including the \\current\\ symlink which is used by IIS as the site root folder. 这会在\\ versions \\中创建一个新的带日期戳的文件夹,更新存储库并更新主repo文件夹中的composer依赖项,对新版本文件夹执行git checkout-index,使用xcopy将具有composer依赖项的Vendor文件夹复制到新版本(因为它被git忽略),然后更新一些符号链接,包括IIS用作站点根文件夹的\\ current \\符号链接。

@echo off
For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set mydate=%%c-%%a-%%b)
For /f "tokens=1-2 delims=/:" %%a in ('time /t') do (set mytime=%%a%%b)
set date=%mydate%_%mytime%

mkdir "C:\inetpub\appname\versions\%date%"

cd "C:\inetpub\appname\repository"
git pull origin master
composer update
git checkout-index -a -f --prefix="C:\inetpub\appname\versions\%date%\\"

cd "C:\inetpub\appname\versions\%date%\\"

xcopy /E /y /q "C:\inetpub\appname\repository\www\app\Vendor" "www\app\Vendor"

del /Q www\app\webroot\files
rmdir www\app\webroot\files

cd "C:\inetpub\appname\"

MKLINK /D "C:\inetpub\appname\versions\%date%\www\app\tmp" "C:\inetpub\appname_tmp"
MKLINK /D "C:\inetpub\appname\versions\%date%\www\app\webroot\files" "E:\appname_files"

rmdir current
MKLINK /D current "C:\inetpub\appname\versions\%date%\www"

appcmd recycle apppool /apppool.name:"Localhost"

Updated answer: 更新的答案:

To get the above working properly, you have to add "call" to the beginning of any line which executes another batch file, eg call composer install 为了使以上内容正常工作,您必须在执行另一批处理文件的任何行的开头添加“ call”,例如call composer install

Sounds like a typo in the script. 听起来像脚本中的错字。 Is it possible for you to paste the script on gist or some code share? 是否可以将脚本粘贴到要点或某些代码共享上? If the composer update is running correctly, then it's something in the way the script is written. 如果composer更新正常运行,则说明编写脚本的方式有所不同。 Also, you should never run composer update in deployment scripts. 另外,您永远不要在部署脚本中运行composer update。 Deployment scripts should only use "composer install" 部署脚本应仅使用“ composer install”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM