6
6
import hudson .model .AbstractProject ;
7
7
import hudson .model .BuildListener ;
8
8
import hudson .model .Descriptor ;
9
+ import hudson .model .Result ;
9
10
import hudson .tasks .BuildStepDescriptor ;
10
11
import hudson .tasks .Builder ;
12
+ import hudson .tools .ToolInstallation ;
11
13
import hudson .util .ArgumentListBuilder ;
12
14
import liquibase .Contexts ;
13
15
import liquibase .Liquibase ;
24
26
import java .util .Properties ;
25
27
26
28
import org .jenkinsci .plugins .liquibase .common .PropertiesParser ;
29
+ import org .jenkinsci .plugins .liquibase .installation .LiquibaseInstallation ;
27
30
import org .kohsuke .stapler .DataBoundConstructor ;
28
31
import org .slf4j .Logger ;
29
32
import org .slf4j .LoggerFactory ;
@@ -79,6 +82,11 @@ public class LiquibaseBuilder extends Builder {
79
82
80
83
private String liquibasePropertiesPath ;
81
84
85
+ private boolean invokeExternal ;
86
+
87
+ private String installationName ;
88
+
89
+
82
90
@ DataBoundConstructor
83
91
public LiquibaseBuilder (String changeLogFile ,
84
92
String username ,
@@ -88,7 +96,9 @@ public LiquibaseBuilder(String changeLogFile,
88
96
String contexts ,
89
97
String databaseEngine ,
90
98
boolean testRollbacks ,
91
- String liquibasePropertiesPath ) {
99
+ String liquibasePropertiesPath ,
100
+ boolean invokeExternal ,
101
+ String installationName ) {
92
102
this .password = password ;
93
103
this .defaultSchemaName = defaultSchemaName ;
94
104
this .url = url ;
@@ -101,7 +111,8 @@ public LiquibaseBuilder(String changeLogFile,
101
111
this .testRollbacks = testRollbacks ;
102
112
this .liquibasePropertiesPath = liquibasePropertiesPath ;
103
113
104
-
114
+ this .invokeExternal = invokeExternal ;
115
+ this .installationName = installationName ;
105
116
}
106
117
107
118
@ Override
@@ -126,13 +137,13 @@ public boolean perform(final AbstractBuild<?, ?> build, Launcher launcher, Build
126
137
action .addFailed (changeSetOptional .get ());
127
138
}
128
139
migrationException .printStackTrace (listener .getLogger ());
129
- throw new RuntimeException ( "Error executing liquibase liquibase database" , migrationException );
140
+ build . setResult ( Result . UNSTABLE );
130
141
} catch (DatabaseException e ) {
131
142
e .printStackTrace (listener .getLogger ());
132
- throw new RuntimeException ( "Error creating liquibase database" , e );
143
+ build . setResult ( Result . FAILURE );
133
144
} catch (LiquibaseException e ) {
134
145
e .printStackTrace (listener .getLogger ());
135
- throw new RuntimeException ( "Error executing liquibase liquibase database" , e );
146
+ build . setResult ( Result . FAILURE );
136
147
} finally {
137
148
if (liquibase .getDatabase () != null ) {
138
149
try {
@@ -150,7 +161,6 @@ private Liquibase createLiquibase(AbstractBuild<?, ?> build,
150
161
ExecutedChangesetAction action ,
151
162
Properties configProperties ) {
152
163
153
-
154
164
Liquibase liquibase ;
155
165
try {
156
166
Database databaseObject = CommandLineUtils .createDatabaseObject (getClass ().getClassLoader (),
@@ -227,6 +237,10 @@ public String getUsername() {
227
237
return username ;
228
238
}
229
239
240
+ public boolean isInvokeExternal () {
241
+ return invokeExternal ;
242
+ }
243
+
230
244
public String getPassword () {
231
245
return password ;
232
246
}
@@ -282,6 +296,7 @@ public void setDriverName(String driverName) {
282
296
public static class DescriptorImpl extends BuildStepDescriptor <Builder > {
283
297
284
298
private List <EmbeddedDriver > embeddedDrivers ;
299
+ private LiquibaseInstallation [] installations ;
285
300
286
301
@ Override
287
302
public boolean isApplicable (Class <? extends AbstractProject > jobType ) {
@@ -299,13 +314,25 @@ public List<EmbeddedDriver> getEmbeddedDrivers() {
299
314
}
300
315
return embeddedDrivers ;
301
316
}
317
+ public LiquibaseInstallation .DescriptorImpl getToolDescriptor () {
318
+ return ToolInstallation .all ().get (LiquibaseInstallation .DescriptorImpl .class );
319
+ }
302
320
303
321
private void initDriverList () {
304
322
embeddedDrivers = Lists .newArrayList (new EmbeddedDriver ("MySQL" , "com.mysql.jdbc.Driver" ),
305
323
new EmbeddedDriver ("PostgreSQL" , "org.postgresql.Driver" ),
306
324
new EmbeddedDriver ("Hypersonic" , "org.hsqldb.jdbcDriver" ),
307
325
new EmbeddedDriver ("H2" , "org.h2.Driver" ));
308
326
}
327
+
328
+ public LiquibaseInstallation [] getInstallations () {
329
+ return installations ;
330
+ }
331
+
332
+ public void setInstallations (LiquibaseInstallation [] installations ) {
333
+ this .installations = installations ;
334
+ save ();
335
+ }
309
336
}
310
337
311
338
}
0 commit comments