請參考 django 設定環境,準備開發環境、建立專案 (假設叫做 demo)...
$ cd ~/myWorkspace
$ source venv/bin/activate
(venv) vagrant@debian:~/myWorkspace$ cd demo
進入 django virtualenv 之後,繼續下面步驟 (以下省略提示符號前文字)
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"
開啟瀏覽器,連接 http://192.168.33.10:8080/ (虛擬機)
- Jenkins 管理首頁
- New Item
- Item name:
demo
- Freestyle project
- Item name:
- Source Code Management
- Git
- Repository URL:
file:///home/vagrant/myWorkspace/demo
- Repository URL:
- Git
- Build Triggers
- Poll SCM
- Schedule:
* * * * *
- Schedule:
- Poll SCM
- Build Environment
- pyenv build wrapper
- The Python version:
3.5.1
- The Python version:
- pyenv build wrapper
- Build
- Execute shell
- Command: shell command
- Execute shell
- Post-build Actions
- Publish Cobertura Coverage Report
- Cobertura xml report pattern:
reports/coverage.xml
- Cobertura xml report pattern:
- Publish JUnit test result report
- Test report XMLs:
reports/junit.xml
- Test report XMLs:
- Report Violations
- pylint:
reports/pylint.report
- pylint:
- Publish Cobertura Coverage Report
- Save
- New Item
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