Automatic deployment of Play 2.6 application using Jenkins
You should have first a project building the Play application.
This project is usually built doing a
clean dist
then archiving the artifact
target/universal/*.zip
as a post-build action.
Then in the deployed project, in the build, we need to execute the following deploy.sh
script.
It consists mainly in 2 steps:
- Copy new artifacts (artifact to copy: target/universal/*.zip, target directory: /opt/yourproject).
- Stop running app, deploy and restart the application.
# Deploy script to update a Play framework application with a new version.
# Take care of stopping running app, unzipping the new one and starting it.
PROJECT=yourproject
TARGET=/opt/$PROJECT
ARTIFACT=$PROJECT-1.0-SNAPSHOT
RUNNING_PID_FILE=$TARGET/$ARTIFACT/RUNNING_PID
echo "=== Copying new version ==="
cp /home/user/$ARTIFACT.zip $TARGET
echo "=== Deploying $ARTIFACT ==="
# Check if a version is running
if [ -e "$RUNNING_PID_FILE" ]; then
# Stop old version
PID=`cat "$RUNNING_PID_FILE"`
echo "Stopping currently running application with pid $PID"
kill $PID
fi
# Remove old version
rm -fr $TARGET/$ARTIFACT
# Deploy new version
unzip $TARGET/$ARTIFACT.zip -d $TARGET
# Start new version
echo "Starting $PROJECT prod webapp"
BUILD_ID=dontKill$PROJECT
nohup bash $TARGET/$ARTIFACT/bin/$PROJECT -Dconfig.file=$TARGET/prod.conf -Dhttp.port=80 -Dhttps.port=443 &>$TARGET/$ARTIFACT/launcher-logs.txt
comments powered by Disqus