持续集成注意事项和高级功能
结果展示
结果展示文件需要使用测试脚本(命令)生成 junit 格式的 XML 文件,该文件路径由系统环境变量 `TEST_RESULT` 指定。例:
nosetests test.py --with-xunit --xunit-file=$TEST_RESULT
结果:
<?xml version="1.0" encoding="utf-8"?> <testsuite name="nosetests" tests="1" errors="0" failures="0" skip="0"> <testcase classname="test.TestSuite" name="test" time="0.033"></testcase> </testsuite>
展示效果如下:
覆盖测试
覆盖测试文件需要使用测试脚本(命令)生成 一个 xml 格式的 coverage 报告,该文件路径由系统环境变量 `TEST_COVERAGE` 指定。例:
coverage xml -o $TEST_COVERAGE test.py
结果:
<?xml version="1.0" ?> <coverage branch-rate="0.5" line-rate="1" timestamp="1445931368445" version="4.0.1"> <!-- Generated by coverage.py: https://coverage.readthedocs.org --> <!-- Based on https://raw.githubusercontent.com/cobertura/web/f0366e5e2cf18f111cbd61fc34ef720a6584ba02/htdocs/xml/coverage-03.dtd --> <sources> <source>/daocloud/builder/src</source> </sources> <packages> <package branch-rate="0.5" complexity="0" line-rate="1" name="."> <classes> <class branch-rate="0.5" complexity="0" filename="test.py" line-rate="1" name="test.py"> <methods/> <lines> <line hits="1" number="1"/> <line hits="1" number="2"/> <line hits="1" number="4"/> <line hits="1" number="5"/> <line hits="1" number="6"/> <line hits="1" number="7"/> <line hits="1" number="8"/> <line hits="1" number="9"/> <line hits="1" number="11"/> <line hits="1" number="12"/> <line branch="true" condition-coverage="50% (1/2)" hits="1" missing-branches="exit" number="14"/> <line hits="1" number="15"/> </lines> </class> </classes> </package> </packages> </coverage>
样例 daocloud.yml
代码参见 GitHub 上的 样例程序 。
version: "2.0" test: image: daocloud/ci-python:2.7 services: - mysql env: - MYSQL_USERNAME="root" - MYSQL_PASSWORD="" - MYSQL_INSTANCE_NAME="test" script: - pip install -r requirements.txt - nosetests test.py --with-xunit --xunit-file=$TEST_RESULT - coverage run --branch test.py - coverage xml -o $TEST_COVERAGE test.py - cat $TEST_RESULT - cat $TEST_COVERAGE
特殊配置
当所推送的最近一次提交信息中带有 [CI SKIP]
或者 [SKIP CI]
字段时,此次推送将不会触发持续集成,例如:
user$ git commit -m 'your message [CI SKIP]' user$ git push
[CI SKIP] 和 [SKIP CI] 不区分大小写,以下形式都是合法的
[ci skip] [CI SKIP] [Ci Skip] [ ci sKip ] [CI SKIp ] [Skip Ci] [skip ci ]