Windows 中的 SVN 预提交挂钩 FTP 上传
我有一个在 Windows 计算机上运行的 SVN 存储库。我需要一个脚本来将任何提交的文件上传到远程 Web 服务器。我已经阅读了预提交挂钩,但我不知道如何实际编写脚本,甚至不知道应该用什么语言编写脚本。似乎脚本需要是 .bat 或 .exe 才能运行在窗户中。
有人有可以在 Windows 机器上运行的脚本吗?我不想上传整个网站,而是上传提交的单个文件。我想要一个预提交挂钩,因为如果 ftp 上传失败,它将向用户提供反馈。
如果您以前做过此操作,请向新手解释整个过程。
I've got an SVN repo running on a Windows machine. I need a script that will upload any committed file to a remote web server. I've read up on pre-commit hooks, but I don't know how to actually write the script, or even in what language it should be written in. Seems like the script needs to be a .bat or .exe to run in windows.
Does anyone have a script that will run on a Windows machine? I'm not looking to upload the entire site, but the individual file(s) committed. I want a pre-commit hook because that will give the user feedback should the ftp upload fail.
If you've done this before, please explain the whole process to a newb.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您希望由于某种原因使提交失败时,可以使用预提交挂钩。您真的想因为 FTP 站点关闭或磁盘已满而导致提交失败吗?
您应该只使用预提交脚本来使开发人员控制下的内容失败,例如缺少必需属性的文件等。这使开发人员有机会纠正问题,然后重新提交提交。
提交后脚本在等待用户完成时仍然会占用用户的终端,但脚本可能会失败并通知用户某些事情失败了,但提交无论如何都会发生。如果您想使用钩子执行此操作,则应该使用提交后钩子而不是预提交钩子。
对于你想做的事情,钩子并不是一个好方法。如果用户提交大量文件怎么办?当你的钩子脚本执行时,他们是否必须坐在那里十分钟左右?
更好的想法是使用连续构建系统,例如 Hudson。 Hudson 将监视您的 Subversion 存储库,并且可以在用户每次提交时执行您想要的 FTP 任务。使用 Hudson,您不会在开发人员等待挂钩完成时束缚他们,并且您拥有每次提交所发生情况的完整日志。
事实上,每个站点都应该使用持续构建服务器。即使您不编译代码,您仍然希望针对每次提交运行测试。
Hudson 甚至还有 FTP 和 SFTP 插件,这可以让您的任务更轻松地完成。而且,您可以在 Hudson 中调用预构建和后构建脚本,因此您可以灵活地执行几乎任何您想做的事情。
Hudson 在 Windows 服务器和 Unix 服务器上运行。它是一个Java进程。
如果您使用的是 Windows,并且没有 PowerShell,则应该下载一些脚本语言并使用它来编写挂钩。 Windows command.exe 处理器中的标准批编程语言不是很灵活或强大。由于钩子在服务器上运行,因此您只需担心钩子是否在单台机器上运行。有些程序使用客户端钩子,如果您编写一个钩子,它必须能够在客户端可能使用的每个系统上运行。
A pre-commit hook is used when you want to be able to fail the commit for some reason. Do you really want to fail a commit be cause your FTP site was down, or the disk was full?
You should only use pre-commit scripts to fail stuff that is under the developer's control such as files that are missing required properties, etc. This gives the developer a chance to correct the problem, then resubmit the commit.
A post-commit script still ties up the user's terminal as they wait for it to complete, but the script can fail and notify the user that something failed, but the commit happens anyway. If you want to do this with hooks, you should be doing it with a post-commit hook and not a pre-commit hook.
For what you want to do, hooks aren't a good way to go. What if the user commits a lot of files? Do they have to sit there for ten or so minutes while your hook script executes?
A better idea is to use a continuous build system like Hudson. Hudson will watch your Subversion repository, and can do the FTP task you want every time a user does a commit. With Hudson, you're not tying up the developer as they wait for the hook to complete, and you have a complete log of what happened with every single commit.
In fact, every site should be using a continuous build server. Even if you don't compile code, you still want to run tests against every commit.
Hudson even has FTP and SFTP plugins which may make your task easier to do. And, you can call pre-build and post-build scripts in Hudson, so you have the flexibility to do almost anything your heart desires.
Hudson runs on Windows servers and Unix servers. It is a Java process.
If you're on Windows, and you don't have PowerShell, you should download some scripting language you and use that to write your hooks. The standard batch programming language in the Windows command.exe processor is not very flexible or powerful. Since hooks run on the server, you only have to worry whether or not your hooks run on a single machine. Some programs use client-side hooks and if you write a hook, it must be capable on running on every single system a client might use.
我认为你需要一个提交后挂钩。
svn hook 实际上可以是任何可执行文件或脚本文件。 在此处查看一些示例
您可以在 Windows 上使用内置的命令行 ftp 客户端。一种方法是将 FTP 命令放入文本文件中,该文件可以从批处理文件生成。示例:
当然,您也可以编写一个程序来执行此操作(例如,在 .Net 中,使用 FtpWebRequest 类),它不必是批处理脚本。
I think you need a post-commit hook.
A svn hook can indeed be any executable or script file. Look here for some samples
You can use the built-in command line ftp client on windows. One way is to put your FTP commands in a text file, which you can generate from a batch file. Example:
Of course, you can also write a program to do this (e.g. in .Net, using the FtpWebRequest class), it doesn't have to be a batch script.