(-_-) .oO (Don't worry about the title, it's a hassle to think about)
I tried to build a Python + Flask web application with Jenkins, so that memo.
The directory structure looks like this (I've deleted the directories I don't want to see).
% tree -d
.
├── env (virtual env)
├── project
│ ├── app
│ ├── conf
│ ├── logs
│ ├── models
│ │ └── mongo
│ ├── services
│ ├── static
│ ├── templates
│ ├── tests
│ │ ├── app
│ │ ├── cover
│ │ ├── data
│ │ ├── models
│ │ │ └── mongo
│ │ ├── services
│ │ ├── utils
│ │ └── view
│ └── utils
└── script
├── deploy (like fabric)
└── tools
There is a directory called project directly under the top directory, and all applications are deployed under it. Also, nosetests can be run from the project directory, and all tests pass at this point. Also, install coverage so that coverage can be obtained. The test execution method is as follows.
% source env/bin/activate
% cd project
% export PYTHONPATH=$PYTHONPATH:`pwd`
% nosetests -v -w tests/ --with-coverage --with-xunit --cover-package=app --cover-package=models --cover-package=services --cover-package=utils --cover-html --cover-xml
In order to prepare the environment with virtualenv in Jenkins, be sure to commit the pip frozen one (or you can execute it in the shell one by one, but pip freeze is easy considering the version).
% source env/bin/activate
% cd project
% pip freeze > requirements.txt
% git add requirements.txt
% git commit
% git push origin master
First, install the VCS plugin you are using and the Cobertura plugin to measure coverage.
Then create a new job and enter the repository path in Source Code Control. Then select Run Shell from Add Build Procedures for your build and type:
if [ ! -d venv ]; then
virtualenv --distribute venv
fi
source venv/bin/activate
cd project
pip install -r requirements.txt
export PYTHONPATH=$PYTHONPATH:$WORKSPACE/project
echo "If you have a copy of the settings or something to do in advance, do it here"
nosetests -v -w tests/ --with-coverage --with-xunit --cover-package=app --cover-package=models --cover-package=services --cover-package=utils --cover-html --cover-xml
sed "s|filename=\"|filename=\"project/|g" $WORKSPACE/project/tests/coverage.xml > $WORKSPACE/project/tests/coverage2.xml
Since the source code of the last sed is not directly under the directory, to solve the problem that the source code cannot be seen in the coverage, add the relative path from the top directory to the path of the coverage measurement result (Reference: [Hudson] “Source code is unavailable.”](Http://stackoverflow.com/questions/2285672/hudson-source-code-is-unavailable/2915958#2915958 “Hudson“ Source code is unavailable. ””))
Next, add two post-build processes. One is to add a JUnit test result summary and copy the following content into the test result XML.
project/nosetests.xml
The other adds a Cobertura coverage report aggregate and copies the following to the Cobertura XML report pattern:
project/tests/coverage2.xml
Now save and run the build.
Maybe you'll be happy to see the dashboard.
Recommended Posts