This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
stage ("Deploy Application to Server") { | |
node { | |
def boxIp = '<target server ip>' | |
ansiColor('xterm') { | |
sh "ssh -oStrictHostKeyChecking=no jenkins@${boxIp} -t -t '(sudo /usr/local/jenkins/deploy.sh ${fullFileName})'" | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
stage ("Copy Artifact file to Repo") { | |
node { | |
def deployTarget = '<target repo server to copy file to>', | |
deployFolder = '<absolute path to target folder which will store all artifacts files>' | |
sh "scp ${applicationZip} jenkins@${deployTarget}:${deployFolder}" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def regExMatch = /\/|\./, | |
// We are going to use the global BUILD_TAG to identify our artifact file. Sometimes the BUILD_TAG might contain unwanted | |
// characters so we are going to strip them out and replace them with dashes | |
safeBuildName = jenkins.branch.MultiBranchProject.rawDecode(env.BUILD_TAG).replaceAll(regExMatch, "-"), | |
artifactFolder = "target", | |
fullFileName = "${safeBuildName}.tar.gz", | |
// Define the final location and file name for the artifact file | |
applicationZip = "${artifactFolder}/${fullFileName}", | |
// List out all of the relative paths to your django apps which your application relies upon | |
// and leave out things which should not get deployed like tests and mocks. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!groovy | |
// This deployment script assumes that there is only a single Jenkins server (master) and there are no agents. | |
// If the setup includes agents, then the stages should be reconfigured to take advantage of additional remote nodes. | |
// This script is assuming that you're using a multi-branch project but the majority directly translates to a regular pipeline project. | |
node { | |
// It's often recommended to run a django project from a virtual environment. | |
// This way you can manage all of your depedencies without affecting the rest of your system. | |
def installed = fileExists 'bin/activate' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
stage ("Run Unit/Integration Tests") { | |
def testsError = null | |
try { | |
sh ''' | |
source ../bin/activate | |
python <relative path to manage.py> jenkins | |
deactivate | |
''' | |
} | |
catch(err) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
stage ("Collect Static files") { | |
sh ''' | |
source bin/activate | |
python <relative path to manage.py> collectstatic --noinput | |
deactivate | |
''' | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
stage ("Install Application Dependencies") { | |
sh ''' | |
source bin/activate | |
pip install -r <relative path to requirements file> | |
deactivate | |
''' | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
stage ("Get Latest Code") { | |
checkout scm | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def installed = fileExists 'bin/activate' | |
if (!installed) { | |
stage("Install Python Virtual Enviroment") { | |
sh 'virtualenv --no-site-packages .' | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!groovy | |
// This deployment script assumes that there is only a single Jenkins server (master) and there are no agents. | |
// If the setup includes agents, then the stages should be reconfigured to take advantage of additional remote nodes. | |
// This script is assuming that you're using a multi-branch project but the majority directly translates to a regular pipeline project. | |
node { | |
// It's often recommended to run a django project from a virtual environment. | |
// This way you can manage all of your depedencies without affecting the rest of your system. | |
def installed = fileExists 'bin/activate' |
NewerOlder