Jenkins auto deploying flask in test env with last build process kill and pipenv

#!/bin/sh
cd $WORKSPACE
export PY=/usr/local/bin/python3
export FLASK_RUN_PORT=4005
$PY -m pip install pipenv
$PY -m pipenv install --dev
export VENV_HOME_DIR=$($PY -m pipenv --venv)
source $VENV_HOME_DIR/bin/activate
flask db upgrade
flask populate-initial-data
export BUILD_ID=XYZapi
$WORKSPACE/killlastbuild.sh
flask run &
deactivate

killlastbuild.sh can have anything inside it depending upon your project requirements. I put 2 process killers to kill background-ed daemon processes from previous build command

ps -Af | grep "xyzapi" | grep -v grep | awk '{print$2}' | head -1 | xargs kill -9
ps -Af | grep "xyzapi" | grep -v grep | awk '{print$2}' | head -1 | xargs kill -9