Skip to content

Latest commit

 

History

History
119 lines (94 loc) · 2.68 KB

django-jenkins.md

File metadata and controls

119 lines (94 loc) · 2.68 KB

django-jenkins

開始之前

請參考 django 設定環境,準備開發環境、建立專案 (假設叫做 demo)...

$ cd ~/myWorkspace
$ source venv/bin/activate
(venv) vagrant@debian:~/myWorkspace$ cd demo

進入 django virtualenv 之後,繼續下面步驟 (以下省略提示符號前文字)

安裝 django-jenkins

pip install django-jenkins

設定專案

修改 demo/settings.py: - 加入 'django_jenkins' App - 加入要跑 jenkins test, report 的 App,例如 calc

INSTALLED_APPS = [
    'behave_django',
    'django_jenkins',
    ...
    'calc',
]

# Jenkins settings
PROJECT_APPS = [
    'calc',
]

JENKINS_TASKS = (
    'django_jenkins.tasks.run_pylint',
)

專案版控

初始化 git repository

$ git init

建立 .gitignore,設定哪些檔案不做版本追蹤

__pycache__
db.sqlite3
.python-version
*.pyc
.*.swp
reports/

上傳 git repository

$ git add .
$ git commit -m "first commit"

設定 Jenkins server

開啟瀏覽器,連接 http://192.168.33.10:8080/ (虛擬機)

  • Jenkins 管理首頁
    • New Item
      • Item name: demo
        • Freestyle project
    • Source Code Management
      • Git
        • Repository URL: file:///home/vagrant/myWorkspace/demo
    • Build Triggers
      • Poll SCM
        • Schedule: * * * * *
    • Build Environment
      • pyenv build wrapper
        • The Python version: 3.5.1
    • Build
    • Post-build Actions
      • Publish Cobertura Coverage Report
        • Cobertura xml report pattern: reports/coverage.xml
      • Publish JUnit test result report
        • Test report XMLs: reports/junit.xml
      • Report Violations
        • pylint: reports/pylint.report
    • Save

shell command

PATH=$WORKSPACE/venv/bin:/usr/local/bin:$PATH

if [ ! -d "venv" ]; then
        virtualenv venv
fi
. venv/bin/activate
pip install -r requirements.txt

python manage.py jenkins --enable-coverage

觀看 reports

Violations report

Coverage report

test result

參考資料