forked from prospero238/liquibase-runner
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/JENKINS-40963-JobDSLintegration' into develop
- Loading branch information
Showing
20 changed files
with
776 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
1.3.0 Release notes | ||
=================== | ||
|
||
Jira Issues | ||
---------------- | ||
|
||
* [JENKINS-40963 Allow Liquibase runner to integrate with Job DSL plugin](https://issues.jenkins-ci.org/browse/JENKINS-40963) | ||
* [JENKINS-33401 Credentials Integration](https://issues.jenkins-ci.org/browse/JENKINS-33401) | ||
* [JENKINS-40816 Provide liquibase dbdoc generation build step](https://issues.jenkins-ci.org/browse/JENKINS-40816) | ||
|
||
Feature Info | ||
---------------- | ||
|
||
**Pipeline Support** | ||
|
||
See [documentation](https://github.com/jenkinsci/liquibase-runner-plugin/blob/develop/src/docs/pipeline.md) regarding | ||
how to incorporate this plugin into your pipeline scripts. | ||
|
||
**DbDoc Generation** | ||
|
||
You can now generate Liquibase's [dbDoc](http://www.liquibase.org/dbdoc/index.html) using the plugin. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
Job DSL Integration | ||
=================== | ||
|
||
|
||
As of version 1.3.0 of Liquibase Runner, you can now use the Job DSL plugin to script liquibase job creation. Here are some examples: | ||
|
||
Minimal Update | ||
-------------- | ||
Just as with manual configuration, providing merely the changelog file will make the plugin use an in-memory H2 database. | ||
``` | ||
job() { | ||
steps { | ||
liquibaseUpdate { | ||
changeLogFile('changeset.xml') | ||
} | ||
} | ||
} | ||
``` | ||
|
||
Update with many parameters | ||
--------------------------- | ||
``` | ||
job() { | ||
steps { | ||
liquibaseUpdate { | ||
changeLogFile('changeset.yml') | ||
testRollbacks(true) | ||
url('jdbc:postgresql://localhost:5432/sample-db') | ||
driverClassname('org.postgresql.Driver') | ||
// instead of driverClassname, you can set databaseEngine to MySQL, Derby, Postgres, Derby, or Hypersonic | ||
databaseEngine('MySQL') | ||
credentialsId('database_password_credentials_id') | ||
liquibasePropertiesPath('/etc/liquibase.properties') | ||
contexts('staging') // can be comma delimited list | ||
// changelog parameters are supplied as a map of key/value pairs | ||
changeLogParameters( [ | ||
"sample.table.name":"blue", | ||
"favorite.food":"spaghetti" | ||
] | ||
) | ||
} | ||
} | ||
} | ||
``` | ||
|
||
Rollback | ||
-------- | ||
The same base configuration fields are available for rollbacks, plus additional ones which control rollback behavior. | ||
|
||
Note that the below example has mutually exclusive rollback options. In practice, you'd either specify rollbackCount, rollbackToTag, rollbackToDate, or rollbackLastHours. | ||
``` | ||
job() { | ||
steps { | ||
liquibaseUpdate { | ||
changeLogFile('changeset.yml') | ||
testRollbacks(true) | ||
url('jdbc:postgresql://localhost:5432/sample-db') | ||
driverClassname('org.postgresql.Driver') | ||
credentialsId('database_password_credentials_id') | ||
rollbackToTag('deploy-2.5') | ||
rollbackCount(2) | ||
rollbackToDate("2016-10-13'T'12:00:00") | ||
rollbackLastHours(3) | ||
} | ||
} | ||
} | ||
``` |
216 changes: 216 additions & 0 deletions
216
src/main/java/org/jenkinsci/plugins/liquibase/dsl/LiquibaseContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,216 @@ | ||
package org.jenkinsci.plugins.liquibase.dsl; | ||
|
||
import javaposse.jobdsl.dsl.Context; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* One context is supplied for all liquibase execution types (be it update, rollback, etc). | ||
*/ | ||
public class LiquibaseContext implements Context { | ||
|
||
protected String databaseEngine; | ||
protected String changeLogFile; | ||
protected String url; | ||
protected String defaultSchemaName; | ||
protected String contexts; | ||
protected String liquibasePropertiesPath; | ||
protected String classpath; | ||
protected String driverClassname; | ||
protected String labels; | ||
private Map<String, String> changeLogParameters; | ||
private String basePath; | ||
private Boolean useIncludedDriver; | ||
private String credentialsId; | ||
protected Integer rollbackCount = 0; | ||
private Integer rollbackLastHours; | ||
private String rollbackToTag ; | ||
private String rollbackToDate; | ||
protected boolean testRollbacks; | ||
private boolean dropAll; | ||
protected boolean tagOnSuccessfulBuild; | ||
private String outputDirectory; | ||
|
||
|
||
void databaseEngine(String databaseEngine) { | ||
this.databaseEngine = databaseEngine; | ||
} | ||
|
||
void changeLogFile(String changeLogFile) { | ||
this.changeLogFile = changeLogFile; | ||
} | ||
|
||
void url(String url) { | ||
this.url = url; | ||
} | ||
|
||
void defaultSchemaName(String defaultSchemaName) { | ||
this.defaultSchemaName = defaultSchemaName; | ||
} | ||
|
||
void contexts(String contexts) { | ||
this.contexts = contexts; | ||
} | ||
|
||
void liquibasePropertiesPath(String liquibasePropertiesPath) { | ||
this.liquibasePropertiesPath = liquibasePropertiesPath; | ||
} | ||
|
||
void credentialsId(String credentialsId) { | ||
this.credentialsId = credentialsId; | ||
} | ||
void classpath(String classpath) { | ||
this.classpath = classpath; | ||
} | ||
|
||
void driverClassname(String driverClassname) { | ||
this.driverClassname = driverClassname; | ||
} | ||
|
||
void labels(String labels) { | ||
this.labels = labels; | ||
} | ||
|
||
void changeLogParameters(Map changeLogParameters) { | ||
this.changeLogParameters = changeLogParameters; | ||
} | ||
|
||
void basePath(String basePath) { | ||
this.basePath = basePath; | ||
} | ||
|
||
void rollbackCount(int rollbackCount) { | ||
this.rollbackCount = rollbackCount; | ||
} | ||
public String getDatabaseEngine() { | ||
return databaseEngine; | ||
} | ||
|
||
public String getChangeLogFile() { | ||
return changeLogFile; | ||
} | ||
|
||
public String getUrl() { | ||
return url; | ||
} | ||
|
||
public String getDefaultSchemaName() { | ||
return defaultSchemaName; | ||
} | ||
|
||
public String getContexts() { | ||
return contexts; | ||
} | ||
|
||
public String getLiquibasePropertiesPath() { | ||
return liquibasePropertiesPath; | ||
} | ||
|
||
public String getClasspath() { | ||
return classpath; | ||
} | ||
|
||
public String getDriverClassname() { | ||
return driverClassname; | ||
} | ||
|
||
public String getLabels() { | ||
return labels; | ||
} | ||
|
||
public Map getChangeLogParameters() { | ||
return changeLogParameters; | ||
} | ||
|
||
public String getBasePath() { | ||
return basePath; | ||
} | ||
|
||
public Boolean getUseIncludedDriver() { | ||
return useIncludedDriver; | ||
} | ||
|
||
public String getCredentialsId() { | ||
return credentialsId; | ||
} | ||
|
||
public String getRollbackToDate() { | ||
return rollbackToDate; | ||
} | ||
|
||
public void rollbackToDate(String rollbackToDate) { | ||
this.rollbackToDate = rollbackToDate; | ||
} | ||
|
||
public String getRollbackToTag() { | ||
return rollbackToTag; | ||
} | ||
|
||
public void rollbackToTag(String rollbackToTag) { | ||
this.rollbackToTag = rollbackToTag; | ||
} | ||
|
||
public Integer getRollbackLastHours() { | ||
return rollbackLastHours; | ||
} | ||
|
||
public void rollbackLastHours(Integer rollbackLastHours) { | ||
this.rollbackLastHours = rollbackLastHours; | ||
} | ||
|
||
public Integer getRollbackCount() { | ||
return rollbackCount; | ||
} | ||
|
||
public void setRollbackCount(int rollbackCount) { | ||
this.rollbackCount = rollbackCount; | ||
} | ||
|
||
public boolean isTagOnSuccessfulBuild() { | ||
return tagOnSuccessfulBuild; | ||
} | ||
|
||
public void tagOnSuccessfulBuild(boolean tagOnSuccessfulBuild) { | ||
this.tagOnSuccessfulBuild = tagOnSuccessfulBuild; | ||
} | ||
|
||
public boolean isDropAll() { | ||
return dropAll; | ||
} | ||
|
||
public void dropAll(boolean dropAll) { | ||
this.dropAll = dropAll; | ||
} | ||
|
||
public boolean isTestRollbacks() { | ||
return testRollbacks; | ||
} | ||
|
||
public void testRollbacks(boolean testRollbacks) { | ||
this.testRollbacks = testRollbacks; | ||
} | ||
|
||
public void outputDirectory(String outputDirectory) { | ||
this.outputDirectory = outputDirectory; | ||
} | ||
|
||
public String getOutputDirectory() { | ||
return outputDirectory; | ||
} | ||
|
||
public String composeChangeLogString() { | ||
StringBuilder sb = new StringBuilder(""); | ||
String result = null; | ||
if (changeLogParameters != null) { | ||
for (String key : changeLogParameters.keySet()) { | ||
sb.append(key).append("=").append(changeLogParameters.get(key)).append("\n"); | ||
} | ||
result = sb.substring(0, sb.length() - 1); | ||
} else { | ||
result = sb.toString(); | ||
} | ||
|
||
|
||
return result; | ||
} | ||
} |
Oops, something went wrong.