Skip to content

Commit 6f2a9b7

Browse files
committed
Added SKIP_MIGRATIONS
1 parent 7bbff51 commit 6f2a9b7

File tree

2 files changed

+41
-30
lines changed

2 files changed

+41
-30
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased] - TBD
8+
- SKIP_MIGRATIONS parameter - You can skip running migrations during tests
89

910
## [v1.1.1] - 11-17-2017
1011
### Fixed

vars/rails.groovy

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ def call(body) {
6767
} else {
6868
env.SKIP_TESTS = config.SKIP_TESTS
6969
}
70+
if (!config.SKIP_MIGRATIONS){
71+
config.SKIP_MIGRATIONS = 'false'
72+
} else {
73+
env.SKIP_MIGRATIONS = config.SKIP_MIGRATIONS
74+
}
7075

7176
node {
7277
timestamps {
@@ -98,26 +103,29 @@ def call(body) {
98103
try {
99104
stage('Setup Environment') {
100105
milestone label: 'Setup Environment'
101-
env.BRANCH_NAME = env.BRANCH_NAME.split('-')[0].toLowerCase()
102-
echo "BRANCH_NAME: ${env.BRANCH_NAME}"
103-
def user_length = "${env.MYSQL_USER}_${env.BRANCH_NAME}".length()
104-
def user_name = "${env.BRANCH_NAME}_${env.MYSQL_USER}"
105-
def db_name = "${env.MYSQL_DATABASE}_${env.BRANCH_NAME}".toLowerCase()
106-
env.MYSQL_USER = user_name
106+
107+
if (config.SKIP_MIGRATIONS == 'false') {
108+
env.BRANCH_NAME = env.BRANCH_NAME.split('-')[0].toLowerCase()
109+
echo "BRANCH_NAME: ${env.BRANCH_NAME}"
110+
def user_length = "${env.MYSQL_USER}_${env.BRANCH_NAME}".length()
111+
def user_name = "${env.BRANCH_NAME}_${env.MYSQL_USER}"
112+
def db_name = "${env.MYSQL_DATABASE}_${env.BRANCH_NAME}".toLowerCase()
113+
env.MYSQL_USER = user_name
107114

108-
if(user_length >= 16) {
109-
def trimmed_username = user_name[0..15]
110-
env.MYSQL_USER = trimmed_username
111-
}
112-
env.MYSQL_DATABASE = db_name
115+
if(user_length >= 16) {
116+
def trimmed_username = user_name[0..15]
117+
env.MYSQL_USER = trimmed_username
118+
}
119+
env.MYSQL_DATABASE = db_name
113120

114-
sql connection: 'test_db', sql: "DROP DATABASE IF EXISTS ${env.MYSQL_DATABASE};"
121+
sql connection: 'test_db', sql: "DROP DATABASE IF EXISTS ${env.MYSQL_DATABASE};"
115122

116-
sql connection: 'test_db', sql: "CREATE DATABASE IF NOT EXISTS ${env.MYSQL_DATABASE};"
117-
echo "SQL: CREATE DATABASE IF NOT EXISTS ${env.MYSQL_DATABASE};"
118-
sql connection: 'test_db', sql: "GRANT ALL ON ${env.MYSQL_DATABASE}.* TO \'${env.MYSQL_USER}\'@\'%\' IDENTIFIED BY \'${env.MYSQL_PASSWORD}\';"
119-
echo "SQL: GRANT ALL ON ${env.MYSQL_DATABASE}.* TO \'${env.MYSQL_USER}\'@\'%\' IDENTIFIED BY \'**************\';"
120-
currentBuild.result = 'SUCCESS'
123+
sql connection: 'test_db', sql: "CREATE DATABASE IF NOT EXISTS ${env.MYSQL_DATABASE};"
124+
echo "SQL: CREATE DATABASE IF NOT EXISTS ${env.MYSQL_DATABASE};"
125+
sql connection: 'test_db', sql: "GRANT ALL ON ${env.MYSQL_DATABASE}.* TO \'${env.MYSQL_USER}\'@\'%\' IDENTIFIED BY \'${env.MYSQL_PASSWORD}\';"
126+
echo "SQL: GRANT ALL ON ${env.MYSQL_DATABASE}.* TO \'${env.MYSQL_USER}\'@\'%\' IDENTIFIED BY \'**************\';"
127+
currentBuild.result = 'SUCCESS'
128+
}
121129
}
122130
} catch(Exception e) {
123131
currentBuild.result = 'FAILURE'
@@ -128,21 +136,23 @@ def call(body) {
128136
}
129137

130138
railsInstallDeps(config)
131-
132-
try {
133-
stage('Load Schema') {
134-
milestone label: 'Load Schema'
135-
retry(2) {
136-
railsRvm('rake db:schema:load')
139+
140+
if (config.SKIP_MIGRATIONS == 'false') {
141+
try {
142+
stage('Load Schema') {
143+
milestone label: 'Load Schema'
144+
retry(2) {
145+
railsRvm('rake db:schema:load')
146+
}
147+
currentBuild.result = 'SUCCESS'
137148
}
138-
currentBuild.result = 'SUCCESS'
139-
}
140-
} catch(Exception e) {
141-
currentBuild.result = 'FAILURE'
142-
if (config.DEBUG == 'false') {
143-
railsSlack(config.SLACK_CHANNEL)
149+
} catch(Exception e) {
150+
currentBuild.result = 'FAILURE'
151+
if (config.DEBUG == 'false') {
152+
railsSlack(config.SLACK_CHANNEL)
153+
}
154+
throw e
144155
}
145-
throw e
146156
}
147157

148158
try {

0 commit comments

Comments
 (0)