Skip to content
Permalink
Browse files
Merge branch 'feature/JENKINS-40963-JobDSLintegration' into develop
  • Loading branch information
prospero238 committed Jan 11, 2017
2 parents d7a80ef + 8efb60a commit 42739adcab67da71bbcbf33f47d2c28beb79c643
Showing with 776 additions and 41 deletions.
  1. +17 −2 pom.xml
  2. +21 −0 src/docs/1.3.0-release-notes.md
  3. +8 −7 src/docs/confluence.txt
  4. +69 −0 src/docs/jobdsl.md
  5. +216 −0 src/main/java/org/jenkinsci/plugins/liquibase/dsl/LiquibaseContext.java
  6. +91 −0 src/main/java/org/jenkinsci/plugins/liquibase/dsl/LiquibaseRunnerDslExtension.java
  7. +197 −0 src/test/java/org/jenkinsci/plugins/liquibase/dsl/LiquibaseRunnerDslExtensionTest.java
  8. +1 −1 src/test/java/org/jenkinsci/plugins/liquibase/evaluator/ExecutedChangesetActionTest.java
  9. +20 −15 src/test/java/org/jenkinsci/plugins/liquibase/integration/ChangesetEvaluatorBuildResultTest.java
  10. +2 −2 src/test/java/org/jenkinsci/plugins/liquibase/integration/DriverSelectionFormTest.java
  11. +6 −6 src/test/java/org/jenkinsci/plugins/liquibase/integration/LiquibasePipelineTest.java
  12. +8 −6 src/test/java/org/jenkinsci/plugins/liquibase/integration/RollbackResultTest.java
  13. +43 −0 src/test/java/org/jenkinsci/plugins/liquibase/matchers/BuildResultMatcher.java
  14. +1 −1 src/test/java/org/jenkinsci/plugins/liquibase/{integration → matchers}/InputCheckedMatcher.java
  15. +1 −1 src/test/java/org/jenkinsci/plugins/liquibase/{integration → matchers}/IsChangeSetDetail.java
  16. +32 −0 src/test/java/org/jenkinsci/plugins/liquibase/matchers/ProjectNameMatcher.java
  17. +10 −0 src/test/resources/dsl/dbdoc.groovy
  18. +9 −0 src/test/resources/dsl/liquibase-update.groovy
  19. +14 −0 src/test/resources/dsl/rollback-dsl.groovy
  20. +10 −0 src/test/resources/dsl/update-with-params.groovy
19 pom.xml
@@ -1,4 +1,5 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
@@ -83,6 +84,20 @@
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>job-dsl</artifactId>
<version>1.56</version>
<optional>true</optional>

</dependency>
<dependency>
<groupId>org.jvnet.hudson</groupId>
<artifactId>xstream</artifactId>
<version>1.4.7-jenkins-1</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
@@ -285,7 +300,7 @@
</plugins>
</build>
<properties>
<logback.configuration.file />
<logback.configuration.file/>
</properties>
</profile>
</profiles>
@@ -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.
@@ -51,14 +51,13 @@ This build step generates Liquibase's dbDoc based on the supplied changelog. Se
It is recommended to use this in conjunction with the [HTMLPublisher plugin|https://wiki.jenkins-ci.org/display/JENKINS/HTML+Publisher+Plugin]






h2. Pipeline Support

All liquibase operations are available to pipeline scripts. See [documentation|https://github.com/jenkinsci/liquibase-runner-plugin/blob/develop/src/docs/pipeline.md] for information and examples.

h2. Job DSL Support

Using the Job DSL plugin you can script liquibase job creation. See [documentation|https://github.com/jenkinsci/liquibase-runner-plugin/blob/develop/src/docs/jobdsl.md] for examples.

h2. Usage Tips

@@ -68,15 +67,17 @@ build slave runs your project, that file will no longer be available, and all ch

h2. Version History

h3. Version History
h3. Version 1.3.0 (Jan ?, 2017)

* [JENKINS-40963|https://issues.jenkins-ci.org/browse/JENKINS-40963] Allow Liquibase runner to integrate with Job DSL plugin

h4. Version 1.2.1 (Jan 9, 2017)
h3. Version 1.2.1 (Jan 9, 2017)

* [JENKINS-40920|https://issues.jenkins-ci.org/browse/JENKINS-40920] Credentials migration fails if project has more than one liquibase builder
* [JENKINS-40919|https://issues.jenkins-ci.org/browse/JENKINS-40919] Upgrading to 1.2.0 of the liquibase plugin may result in old-data warning


h4. Version 1.2.0 (Jan 7, 2017)
h3. Version 1.2.0 (Jan 7, 2017)

* [JENKINS-33401|https://issues.jenkins-ci.org/browse/JENKINS-33401] Credentials Integration
* [JENKINS-40816|https://issues.jenkins-ci.org/browse/JENKINS-40816] Provide liquibase dbdoc generation build step
@@ -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)
}
}
}
```
@@ -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;
}
}

0 comments on commit 42739ad

Please sign in to comment.