Created
December 20, 2024 03:08
-
-
Save beisong7/3934632768839472425093b5d7b24a8b to your computer and use it in GitHub Desktop.
jenkins deployment
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
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