带有 Django 和 Python 的 Atlassian Bamboo - 可能吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1419629/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Atlassian Bamboo with Django & Python - Possible?
提问by TM.
At my company, we currently use Atlassian Bamboofor our continuous integration tool. We currently use Java for all of our projects, so it works great.
在我的公司,我们目前使用Atlassian Bamboo作为我们的持续集成工具。我们目前在所有项目中都使用 Java,因此效果很好。
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.
但是,我们正在考虑将 Django + Python 用于我们的新应用程序之一。我想知道是否可以为此使用 Bamboo。
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).
首先,让我说我对 Bamboo 的熟悉程度很低,因为我只使用过它,没有配置过它(除了简单的更改,比如更改构建的 svn checkout 目录)。
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.
显然,仅仅运行构建并没有多大意义(因为 Python 项目并没有真正构建),但我希望能够使用 Bamboo 来运行测试套件,以及使用 Bamboo 来部署将最新代码添加到我们的各种测试环境中,就像我们处理 Java 项目一样。
Does Bamboo support this type of thing with a Python project?
Bamboo 在 Python 项目中支持这种类型的东西吗?
采纳答案by John Paulett
Bamboo essentially just runs a shell script, so this could just as easily be:
Bamboo 本质上只是运行一个 shell 脚本,所以这很容易:
./manage.py test
as it typically is:
因为它通常是:
mvn clean install
or:
或者:
ant compile
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 postabout using xmlrunner.py to get Python working with Hudson. Also take a look at NoseXUnit.
您可能需要将 Django 测试运行程序的输出转换为传统的 JUnit XML 输出,以便 Bamboo 可以为您提供有关通过了多少测试的漂亮图表。看看这篇关于使用 xmlrunner.py 让 Python 与Hudson一起工作的帖子。也看看NoseXUnit。
回答by Raffi
You can even add a bootstrap for pip and virtualenv on a clean environment quite easily, which is cool:
您甚至可以很容易地在干净的环境中为 pip 和 virtualenv 添加引导程序,这很酷:
wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py --root=${bamboo.build.working.directory}/tmp --ignore-installed
export PATH=${bamboo.build.working.directory}/tmp/usr/local/bin:$PATH
export PYTHONPATH=${bamboo.build.working.directory}/tmp/usr/local/lib/python2.7/dist-packages:$PYTHONPATH
pip install --root=${bamboo.build.working.directory}/tmp --ignore-installed virtualenv
virtualenv virtual_tmp
cd virtual_tmp
. bin/activate
echo Pip is located `which pip`
pip install django
pip install djangorestframework
Warning, source bin/activate
does not work as the inline script tasks are stored into an sh file (so bash
run it in sh
compatibility mode).
警告,source bin/activate
由于内联脚本任务存储在 sh 文件中,因此不起作用(因此请bash
在sh
兼容模式下运行它)。
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:
更好的是,我们可以在它上面运行单元测试,带有可以被竹子的 JUnit 解析的 xml 输出:
pip install unittest-xml-reporting
python manage.py test --noinput --testrunner="xmlrunner.extra.djangotestrunner.XMLTestRunner"
回答by saaj
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.
事实证明这是可能的。有两个主要的集成任务:测试运行器结果和代码覆盖率结果。我假设正常的 Python 3 代码库和标准unittest
测试套件。
Test runner
测试运行器
Bamboo expects test runner results in JUnit XML format. There is separate test runneron 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.
Bamboo 需要JUnit XML 格式的测试运行程序结果。Cheese Shop 上有单独的测试运行器能够产生这样的输出,但是它需要你编写一些代码来运行它,这并不好。保持代码库完整的更好方法是使用pytest的功能。
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.
Bamboo 仅支持 Atlassian Clover 的 XML 格式。这里的重要说明是,您不需要启用 Atlassian Clover 插件(以及需要花费一些钱的许可证)。Bamboo 可以独立工作。
Python de facto standard code coverage tool, coverage, produces somewhat Cobertura XML format, but there's a converter. There's a pytest pluginfor integration with the coverage tool.
Python事实上的标准代码覆盖工具coverage产生了某种Cobertura XML格式,但有一个转换器。有一个用于与覆盖工具集成的pytest 插件。
Solution
解决方案
Here's the Toxenvironment where I used pytest to make both Bamboo integrations work.
这是我使用 pytest 使 Bamboo 集成工作的Tox环境。
[tox]
envlist = py34
skipsdist = True
[testenv]
setenv = LANG=C.UTF-8
basepython = python3.4
deps = -r{toxinidir}/requirements.txt
[testenv:bamboo]
commands =
py.test --junitxml=results.xml \
--cov=project_name --cov-config=tox.ini --cov-report=xml \
--cov-report=html project_name/test
coverage2clover -i coverage.xml -o clover.xml
deps =
{[testenv]deps}
pytest
pytest-cov
coverage2clover
# read by pytest
[pytest]
python_files = *.py
# read by coverage
[run]
omit=project_name/test/*,project_name/__main__.py
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 read tox.ini
automatically. pytest-cov bypasses to .coveragerc
, but because it's also an INI file, tox.ini
fits.
请注意, pytest 和 pytest-cov 都tox.ini
用于命令行不支持的配置。它再次使您免于在 repo 的根目录中出现额外的混乱。pytest 尝试tox.ini
自动读取。pytest-cov 绕过到.coveragerc
,但因为它也是一个 INI 文件,tox.ini
适合。
On Bamboo side add a script taskthat runs tox -e bamboo
. Then add JUnit parse taskto the job. In its dialogue, under Specify custom results directoriesput results.xml
.
竹边添加脚本任务是运行tox -e bamboo
。然后将JUnit 解析任务添加到作业中。在其对话中,在指定自定义结果目录下放置results.xml
.
Coverage configuration is done other way.
覆盖配置以其他方式完成。
- Open Miscellaneoustab of your job
- Check Use Clover to collect Code Coverage for this build
- Select Clover is already integrated into this build and a clover.xml file will be produced
- Type
clover.xml
into Clover XML Location
- 打开您工作的其他选项卡
- 选中使用 Clover 收集此构建的代码覆盖率
- Select Clover 已经集成到这个构建中,并且会生成一个 clover.xml 文件
- 键入
clover.xml
到四叶草XML位置
At this point in your next build you will see total coverage and two charts: Coverage historyand 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.
此时,在您的下一个构建中,您将看到总覆盖率和两个图表:Coverage history和Lines of code history。由覆盖工具生成交互式 HTML 也很好,因此您可以深入到特定的代码行。
The settings made above (at least in Bamboo 5.7) has created Clover Report (System)in Artifactjob's tab. Open it and set htmlcov
to Locationfield, and *.*
to Copy pattern. Bamboo will now collect the HTML reports. You can see it at Clovertab of your plan.
上面所做的设置(至少在 Bamboo 5.7 中)已在Artifact作业的选项卡中创建了Clover Report(系统)。打开它并设置为Location字段,并设置为Copy pattern。Bamboo 现在将收集 HTML 报告。您可以在计划的Clover选项卡中看到它。htmlcov
*.*
回答by user3277225
If you use pytest you can simply use py.test --junitxml=/path/to/results/xml/file.xml
如果你使用 pytest 你可以简单地使用 py.test --junitxml=/path/to/results/xml/file.xml