交换测试数据库连接代码作为构建后步骤
在推广或部署构建时,我想自动交换单个数据库连接文件。这可以作为构建后步骤或部署前的预打包步骤来完成。
被换出的文件是测试文件;被交换的文件应该具有真实的数据库连接配置。
这怎么能做到呢?我使用 Hudson 作为 CI 服务器(如果有帮助的话),并使用 GitHub 作为 SCM。
恕我直言,手动交换文件充满了人为错误,并且可能会被完全忘记。此外,它还增加了一件事情要做,并阻碍了持续部署周期的势头。
When promoting or deploying a build, I'd like to automate swapping out a single database connection file. This could be done as either a post-build step or as a pre-packaging step before deployment.
The file that's being swapped out is a test file; the file being swapped in should have the real database connection configuration.
How can this be done? I use Hudson as the CI server, if that helps, and use GitHub for SCM.
Manual swapping of the files, IMHO, is fraught with human error and can be altogether forgotten. Plus it adds just one more thing to do and impedes the momentum of a continuous deployment cycle.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许您不需要替换整个文件。作为部署脚本的一部分,我们使用 powershell 读取配置文件,并使用一些 xpath 魔法来查找数据库连接字符串并将其更改为测试/生产设置,具体取决于我们部署的位置。
实际上它是一个搜索和替换。
以下是用于修改 .NET Web 配置文件的代码片段,但也可以对其他基于 xml 的配置文件执行相同的操作。
Maybe you don't need to replace the entire file. As part of a deployment script we use powershell to read the config file and use a bit of xpath magic to find and change the database connection strings to test/production settings depending on where we're deploying.
Effectively its a search and replace.
The following is a snippet for modifying a .NET web config file but the same could be done for other xml based configuration files.
Windows
由于我没有 powershell:我基于 这篇博文。请注意此方法的一些限制。
linux/Unix
了解如何使用 sed(手册页)。如果您有 cygwin,您也可以使用 sed。
Windows
Since I don't have powershell: I implemented a search and replace based on this blog post. Be aware of a few limitations of this approach.
linux/Unix
Learn how to use sed (man pages). If you have cygwin, you can use sed as well.