diff --git a/Jenkinsfile b/Jenkinsfile index a2185455d..65aae2300 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -6,11 +6,13 @@ pipeline { disableConcurrentBuilds() } environment { - PROJECT_NAME = 'salix' - REGISTRY = 'registry.verdnatura.es' - DOCKER_HOST_1 = 'vch1.verdnatura.es' - DOCKER_HOST_2 = 'vch2.verdnatura.es' - TAG = "${env.BRANCH_NAME}" + PROJECT_NAME = 'salix' + REGISTRY = 'registry.verdnatura.es' + DOCKER_HOST_1 = 'vch1.verdnatura.es' + DOCKER_HOST_2 = 'vch2.verdnatura.es' + PORT_MASTER = '5002' + PORT_TEST = '5001' + TAG = "${env.BRANCH_NAME}" } stages { stage('Checkout') { @@ -29,10 +31,10 @@ pipeline { switch (env.BRANCH_NAME) { case 'master': - env.PORT = 5002 + env.PORT = PORT_MASTER break case 'test': - env.PORT = 5001 + env.PORT = PORT_TEST break } switch (env.BRANCH_NAME) { @@ -126,6 +128,21 @@ pipeline { } } } + stage('Database') { + when { anyOf { + branch 'test' + }} + steps { + configFileProvider([ + configFile(fileId: "config.${env.NODE_ENV}.ini", + variable: 'MYSQL_CONFIG') + ]) { + sh 'cp "$MYSQL_CONFIG" db/config.$NODE_ENV.ini' + } + + sh 'db/import-changes.sh -f $NODE_ENV' + } + } stage('Cleanup') { when { anyOf { branch 'test' diff --git a/db/.gitignore b/db/.gitignore index 162fe6938..34fb91784 100644 --- a/db/.gitignore +++ b/db/.gitignore @@ -1,2 +1 @@ -config.production.ini -config.test.ini \ No newline at end of file +config.*.ini diff --git a/db/import-changes.sh b/db/import-changes.sh index 498390b51..de963674f 100755 --- a/db/import-changes.sh +++ b/db/import-changes.sh @@ -48,7 +48,8 @@ if [ -z "$ENV" ]; then ENV="test" fi -INI_FILE="config.$ENV.ini" +DIR="$(dirname "${BASH_SOURCE[0]}")" +INI_FILE="$DIR/config.$ENV.ini" if [ ! -f "$INI_FILE" ]; then echo "Config file doesn't exists: $INI_FILE" @@ -59,7 +60,8 @@ echo "[INFO] Config file: $INI_FILE" echo "[INFO] Applying changes" # Import changes -for file in install/changes/*.sql; do + +for file in $DIR/install/changes/*.sql; do echo "[INFO] -> $file" mysql --defaults-file="$INI_FILE" < $file done