Skip to content

Instantly share code, notes, and snippets.

@BillyPurvis
Last active July 2, 2018 20:57
Show Gist options
  • Save BillyPurvis/ee47f15936f65c2f46ce3b5bca15f0ea to your computer and use it in GitHub Desktop.
Save BillyPurvis/ee47f15936f65c2f46ce3b5bca15f0ea to your computer and use it in GitHub Desktop.
Full Build Stages Jenkinsfile
String branchName = env.BRANCH_NAME
String gitCredentials = "CREDENTIAL_ID"
String repoUrl = "https://github.com/username/repo-name.git"
// Server Credentials ID
String testCredentials = "CREDENTIAL_ID"
String ip = "127.0.0.1" // Server IP goes here
String usr_dir = "example" // Server user and path
node {
// Start Stages
stage('Clone') {
// Clones the repository from the current branch name
echo 'Make the output directory'
sh 'mkdir -p build'
echo 'Cloning files from (branch: "' + branchName + '" )'
dir('build') {
git branch: branchName, credentialsId: gitCredentials, url: repoUrl
}
}
stage('Build') {
echo 'Building Project...'
dir('build') {
sh 'tar -czf buildFiles.tar.gz app composer.* config cron hooks package-lock.json package.json public resources routes server.php'
}
}
stage('Distribute') {
echo 'Deploying code to the mainframe *cue Matrix theme*'
sshagent([sshCredentials]) {
sh 'scp -oStrictHostKeyChecking=no build/buildFiles.tar.gz ' + usr_dir + '@' + ip + ':/home/' + usr_dir + '/public_html'
}
}
stage('Clean') {
echo 'Removing old files...'
sshagent([sshCredentials]) {
sh 'ssh ' + usr_dir + '@' + ip + ' "cd public_html && rm -rf config hooks package-lock.json package.json public resources routes"'
}
}
stage('Deploy') {
echo "Summoning our lord and saviour tar to unzip files "
sshagent([sshCredentials]) {
sh 'ssh ' + usr_dir + '@' + ip + ' "cd public_html && tar -xf buildFiles.tar.gz && rm -f buildFiles.tar.gz && ./post-deployment.sh"'
sh 'ssh ' + usr_dir + '@' + ip + ' "cd public_html && php artisan cache:clear && php artisan view:clear"'
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment