Vienna with Python + Flask web app on Jenkins

(-_-) .oO (Don't worry about the title, it's a hassle to think about)

Introduction

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

What to do before launching Jenkins

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

Work on the Jenkins side

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

Vienna with Python + Flask web app on Jenkins
Easy web app with Python + Flask + Heroku
Web application with Python + Flask ② ③
Web application with Python + Flask ④
Sample to put Python Flask web app on Azure App Service (Web App)
(Failure) Deploy a web app made with Flask on heroku
Easy deep learning web app with NNC and Python + Flask
[Python] Run Flask on Google App Engine
Daemonize a Python web app with Supervisor
Download files on the web with Python
Create a simple web app with flask
Run Python web apps on NGINX + NGINX Unit + Flask
Launch a web server with Python and Flask
Run Flask on CentOS with python3.4, Gunicorn + Nginx.
Programming with Python Flask
Deploy a Python 3.6 / Django / Postgres web app on Azure
Easy machine learning with scikit-learn and flask ✕ Web app
Parse and visualize JSON (Web application ⑤ with Python + Flask)
PIL with Python on Windows 8 (for Google App Engine)
Web scraping with python + JupyterLab
Web application development with Flask
Web API with Python + Falcon
Web scraping beginner with python
Streamline web search with python
How to deploy a web app made with Flask to Heroku
Save images on the web to Drive with Python (Colab)
SNS Python basics made with Flask
Web scraping with Python ① (Scraping prior knowledge)
Getting Started with Python Web Applications
Web scraping with Python First step
I tried web scraping with python.
Run the app with Flask + Heroku
Monitor Python web apps with Prometheus
[Python] Use Basic/Digest authentication with Flask
Get web screen capture with python
Creating a simple app with flask
Deploy Flask app on heroku (bitterly)
Deploy the Flask app on Heroku
Notes on using rstrip with python.
Deploy the Flask app on heroku
Getting started with Python 3.8 on Windows
Application development with Docker + Python + Flask
[Memo] Tweet on twitter with python
The first artificial intelligence. Challenge web output with python. ~ Flask introduction
Web application created with Python + Flask (using VScode) # 1-Virtual environment construction-
Build a Flask / Bottle-like web application on AWS Lambda with Chalice
Create a Python3.4 + Nginx + uWSGI + Flask Web application execution environment with haste using pyenv on Ubuntu 12.04
Azure table storage with PTVS Flask app
Run servo with Python on ESP32 (Windows)
Deploy flask app with mod_wsgi (using pipenv)
Getting Started with Flask with Azure Web Apps
Deploy a Python app on Google App Engine and integrate it with GitHub
Play like a web app with ipywidgets
Getting Started with Python Web Scraping Practice
Uncle SES modernizes VBA app with Python
POST variously with Python and receive with Flask
Page cache in Python + Flask with Flask-Caching
Data integration from Python app on Linux to Amazon Redshift with ODBC
A memo with Python2.7 and Python3 on CentOS
Map rent information on a map with python
Follow active applications on Mac with Python