Atlassian Bamboo 与 Django 和 Django Python——可能吗?
在我的公司,我们目前使用 Atlassian Bamboo 作为我们的持续集成工具。目前我们所有的项目都使用 Java,所以它运行得很好。
但是,我们正在考虑将 Django + Python 用于我们的新应用程序之一。我想知道是否可以使用 Bamboo 来实现这一点。
首先,我要说的是,我对 Bamboo 的熟悉程度很低,因为我只使用过它,没有配置过它(除了简单的更改,例如更改构建的 svn checkout 目录)。
显然,仅仅运行构建并没有多大意义(因为 Python 项目并没有真正构建),但我希望能够使用 Bamboo 来运行测试套件,以及使用 Bamboo 来部署就像我们处理 Java 项目一样,将最新代码添加到我们的各种测试环境中。
Bamboo 在 Python 项目中支持这种类型的东西吗?
At my company, we currently use Atlassian Bamboo for our continuous integration tool. We currently use Java for all of our projects, so it works great.
However, we are considering using a Django + Python for one of our new applications. I was wondering if it is possible to use Bamboo for this.
First off, let me say that I have a low level of familiarity with Bamboo, as I've only ever used it, not configured it (other than simple changes like changing the svn checkout directory for a build).
Obviously there isn't a lot of point in just running a build (since Python projects don't really build), but I'd like to be able to use Bamboo for running the test suite, as well as use bamboo to deploy the latest code to our various test environments the way we do with our Java projects.
Does Bamboo support this type of thing with a Python project?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Bamboo 本质上只是运行一个 shell 脚本,所以这可能很容易:
就像通常那样:
或者:
您可能必须将 Django 测试运行器的输出按摩到传统的 JUnit XML 输出中,以便 Bamboo 可以为您提供漂亮的图表通过了多少测试。查看这篇文章,了解如何使用 xmlrunner.py 让 Python 工作与 Hudson。另请查看 NoseXUnit。
Bamboo essentially just runs a shell script, so this could just as easily be:
as it typically is:
or:
You may have to massage to output of the Django test runner into traditional JUnit XML output, so that Bamboo can give you pretty graphs on how many tests passed. Look at this post about using xmlrunner.py to get Python working with Hudson. Also take a look at NoseXUnit.
您甚至可以在干净的环境中轻松添加 pip 和 virtualenv 的引导程序,这很酷:
警告,
source bin/activate
不起作用,因为内联脚本任务存储在 sh 文件中(因此bash
以sh
兼容模式运行)。编辑
更好的是,我们可以在它的顶部运行单元测试,并使用可由bamboo 的 JUnit 解析的 xml 输出:
You can even add a bootstrap for pip and virtualenv on a clean environment quite easily, which is cool:
Warning,
source bin/activate
does not work as the inline script tasks are stored into an sh file (sobash
run it insh
compatibility mode).Edit
Even better, we can run unit tests on the top of it, with xml outputs that can be parsed by the JUnit of bamboo:
事实证明这是可能的。有两个主要的集成任务:测试运行器结果和代码覆盖率结果。我假设使用正常的 Python 3 代码库和标准
unittest
测试套件。测试运行程序
Bamboo 期望测试运行程序结果采用 JUnit XML 格式 。 Cheese Shop 上有单独的测试运行程序能够产生这样的输出,但是它需要您编写一些代码来运行它,这不太好。保持代码库完整的更好方法是使用 pytest 的功能。
代码覆盖率
Bamboo 仅支持 Atlassian Clover 的 XML 格式。这里重要的注意事项是,您不需要启用 Atlassian Clover 插件(以及需要花费一些钱的许可证)。竹子可以自行发挥作用。
Python事实上的标准代码覆盖率工具,覆盖率,产生了一些
Cobertura XML 格式,但有一个转换器。有一个 pytest 插件,用于与覆盖率工具集成。
解决方案
这是 Tox 环境,我在其中使用 pytest 使两个 Bamboo 集成都能工作。
请注意,pytest 和 pytest-cov 都使用 tox.ini 进行命令行不支持的配置。它再次避免了您的存储库根目录中出现额外的混乱。 pytest 尝试自动读取
tox.ini
。 pytest-cov 绕过.coveragerc
,但因为它也是一个 INI 文件,所以tox.ini
适合。在 Bamboo 端添加一个运行
tox -eamboo< 的 脚本任务 /代码>。然后将 JUnit 解析任务 添加到作业中。在其对话框中,在指定自定义结果目录下放置
results.xml
。覆盖范围配置以其他方式完成。
clover.xml
此时,在您的下一个版本中,您将看到总覆盖率和两个图表:< em>覆盖率历史记录和代码行历史记录。使用覆盖率工具生成交互式 HTML 也很好,这样您就可以深入到特定的代码行。
上述设置(至少在 Bamboo 5.7 中)已在 Artifact 作业选项卡中创建了 Clover 报告(系统)。打开它并将
htmlcov
设置为 位置 字段,将*.*
设置为复制模式。 Bamboo 现在将收集 HTML 报告。您可以在计划的Clover选项卡中看到它。It turns out it is possible. There are two major integration tasks: test runner results and code coverage results. I assume normal Python 3 codebase and standard
unittest
test suite.Test runner
Bamboo expects test runner results in JUnit XML format. There is separate test runner on the Cheese Shop able to produce such output, but it would require you to write a little code to run it, which is not nice. Better way which keeps the codebase intact is to use pytest's features.
Code coverage
Bamboo only supports the XML format of Atlassian Clover. Important note here is that you don't need Atlassian Clover plugin enabled (and license for it which costs some bucks). Bamboo works on its own.
Python de facto standard code coverage tool, coverage, produces somewhat
Cobertura XML format, but there's a converter. There's a pytest plugin for integration with the coverage tool.
Solution
Here's the Tox environment where I used pytest to make both Bamboo integrations work.
Note that both pytest and pytest-cov use
tox.ini
for the configuration that is not supported on command line. It again saves your from having additional clutter in root of your repo. pytest tries to readtox.ini
automatically. pytest-cov bypasses to.coveragerc
, but because it's also an INI file,tox.ini
fits.On Bamboo side add a script task that runs
tox -e bamboo
. Then add JUnit parse task to the job. In its dialogue, under Specify custom results directories putresults.xml
.Coverage configuration is done other way.
clover.xml
into Clover XML LocationAt this point in your next build you will see total coverage and two charts: Coverage history and Lines of code history. It's also nice to have interactive HTML produced by coverage tool, so you can drill down to certain line of code.
The settings made above (at least in Bamboo 5.7) has created Clover Report (System) in Artifact job's tab. Open it and set
htmlcov
to Location field, and*.*
to Copy pattern. Bamboo will now collect the HTML reports. You can see it at Clover tab of your plan.如果您使用 pytest,则只需使用 py.test --junitxml=/path/to/results/xml/file.xml
If you use pytest you can simply use
py.test --junitxml=/path/to/results/xml/file.xml