Skip to content

Instantly share code, notes, and snippets.

@beisong7
Created December 20, 2024 03:08
Show Gist options
  • Save beisong7/3934632768839472425093b5d7b24a8b to your computer and use it in GitHub Desktop.
Save beisong7/3934632768839472425093b5d7b24a8b to your computer and use it in GitHub Desktop.
jenkins deployment
pipeline {
agent any
environment {
SSH_CRED = credentials('server-key')
def CONNECT = 'ssh -o StrictHostKeyChecking=no [email protected]'
}
stages {
stage('Build') {
steps {
echo 'building app'
sh "pwd"
sh "ls"
sh "zip -r webapp.zip ."
sh "ls"
}
}
stage('Deploy') {
steps {
echo 'Deploying app'
sshagent(['server-key']) {
sh 'scp -o StrictHostKeyChecking=no -i $SSH_CRED webapp.zip [email protected]:/home/ubuntu'
sh '$CONNECT "sudo apt install zip -y"'
sh '$CONNECT "sudo rm -rf /var/www/html/"'
sh '$CONNECT "sudo mkdir /var/www/html/"'
sh '$CONNECT "sudo unzip webapp.zip -d /var/www/html/"'
}
}
}
stage('Clean-Up') {
steps {
echo 'Remove existing files'
deleteDir()
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment