From e69f78269edbcfb5f2bab35cef1162529ecabcaa Mon Sep 17 00:00:00 2001 From: Hosick Date: Mon, 31 May 2021 05:10:51 +0900 Subject: [PATCH] chore: Blue/Green Deployment Test --- Jenkinsfile | 146 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..1869bd6 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,146 @@ +def mainBranch = false + +pipeline { + agent any + environment { + PATH = "/opt/gradle/gradle-6.3/bin:$PATH" + SLACK_CHANNEL = '#jenkins-notification' + } + + stages { + + stage('Git Checkout') { + steps { + checkout scm + echo 'Git Checkout Success!' + } + } + + stage('Test') { + steps { + sh 'gradle test' + echo 'test success' + } + + /* post { + failure { + slackSend (channel: SLACK_CHANNEL, color: '#F01717', message: "Test Failed '[${env.BUILD_NUMBER}]' (${env.BUILD_URL})") + } + } */ + } + + stage('Build') { + steps { + sh 'gradle clean build --exclude-task test --exclude-task asciidoctor' + echo 'build success' + } + + /* post { + success { + slackSend (channel: SLACK_CHANNEL, color: '#00FF00', message: "Successful testing and build '[${env.BUILD_NUMBER}]' (${env.BUILD_URL})") + } + + failure { + slackSend (channel: SLACK_CHANNEL, color: '#F01717', message: "Build Failed '[${env.BUILD_NUMBER}]' (${env.BUILD_URL})") + } + } */ + } + + stage('Check Branch') { + when { + branch 'main' + } + + steps { + mainBranch = true + } + } + + stage('Idle Port Stop') { + when { + expression { + mainBranch + } + } + + steps { + steps([$class: 'BapSshPromotionPublisherPlugin']) { + sshPublisher( + continueOnError: false, failOnError: true, + publishers: [ + sshPublisherDesc( + configName: "shoe-auction-reverse-proxy", + verbose: true, + transfers: [ + sshTransfer( + execCommand: "sh start.sh" + ) + ] + ) + ] + ) + } + } + } + + stage('Deploy To Idle Port') { + when { + expression { + mainBranch + } + } + + steps([$class: 'BapSshPromotionPublisherPlugin']) { + sshPublisher( + continueOnError: false, failOnError: true, + publishers: [ + sshPublisherDesc( + configName: "shoe-auction-reverse-proxy", + verbose: true, + transfers: [ + sshTransfer( + execCommand: "sh health.sh" + ) + ] + ) + ] + ) + } + } + + stage('Check Health And Switch Ports') { + when { + expression { + mainBranch + } + } + + steps([$class: 'BapSshPromotionPublisherPlugin']) { + sshPublisher( + continueOnError: false, failOnError: true, + publishers: [ + sshPublisherDesc( + configName: "shoe-auction-reverse-proxy", + verbose: true, + transfers: [ + sshTransfer( + execCommand: "sh stop.sh" + ) + ] + ) + ] + ) + } + + /* post { + success { + slackSend (channel: SLACK_CHANNEL, color: '#00FF00', message: "Health check and deployment successful '[${env.BUILD_NUMBER}]' (${env.BUILD_URL})") + } + + failure { + slackSend (channel: SLACK_CHANNEL, color: '#F01717', message: "Health check and deployment failure '[${env.BUILD_NUMBER}]' (${env.BUILD_URL})") + } + } */ + } + } +} \ No newline at end of file