Merge pull request #37 from beaniejoy/feature/33

Jenkins Pipeline에 flyway migration 단계 추가 적용
This commit is contained in:
Hanbin Lee
2023-03-04 00:38:03 +09:00
committed by GitHub
4 changed files with 26 additions and 9 deletions

View File

@@ -1,19 +1,25 @@
pipeline {
agent any
tools {
jdk("openjdk-17")
}
stages {
stage('Init') {
steps {
sh 'printenv'
script {
sh 'whoami'
sh 'printenv'
FLYWAY_CONFIG = '/home/ec2-user/flyway/flyway.conf'
MIGRATION_SCRIPT = './script/db_migration.sh'
}
}
}
stage('Github clone') {
stage('DB Migrate') {
steps {
git branch: '${BUILD_BRANCH}', url: 'https://github.com/beaniejoy/dongne-cafe-api.git'
sh """
chmod 755 ${MIGRATION_SCRIPT}
/bin/bash ${MIGRATION_SCRIPT} ${FLYWAY_CONFIG}
"""
}
}

View File

@@ -19,8 +19,7 @@ flyway {
baselineDescription = "Start Flyway Migration!"
baselineOnMigrate = true
baselineVersion = "000"
locations = arrayOf("filesystem:./migration", "filesystem:./seed")
configFiles = arrayOf("conf/flyway.conf")
configFiles = arrayOf(System.getProperty("config") ?: "flyway.conf")
cleanDisabled = false // activate flywayClean
ignoreMigrationPatterns = arrayOf("*:pending") // ignore validating pending(대기) state
}

View File

@@ -1,4 +1,5 @@
flyway.url=jdbc:mysql://localhost:3306/dongne?autoreconnect=true&characterEncoding=utf8&serverTimezone=Asia/Seoul
flyway.user=root
flyway.password=beaniejoy
flyway.driver=com.mysql.cj.jdbc.Driver
flyway.driver=com.mysql.cj.jdbc.Driver
flyway.locations=filesystem:db/migration,db/seed

11
script/db_migration.sh Normal file
View File

@@ -0,0 +1,11 @@
#!/bin/bash
echo "================ 1. Flyway Info ================"
./gradlew :db:flywayInfo -Dconfig=$1
echo "================ 2. Flyway Validate ============"
./gradlew :db:flywayValidate -Dconfig=$1
echo "================ 3. Flyway Migrate ============="
./gradlew :db:flywayMigrate -Dconfig=$1