Skip to content

Commit

Permalink
JENKINS-40963 Job DSL integration
Browse files Browse the repository at this point in the history
Creation of extensions for use by dsl plugin
doc updates
  • Loading branch information
prospero238 committed Jan 11, 2017
1 parent d7a80ef commit 5585a30
Show file tree
Hide file tree
Showing 13 changed files with 730 additions and 9 deletions.
19 changes: 17 additions & 2 deletions 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>
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -285,7 +300,7 @@
</plugins>
</build>
<properties>
<logback.configuration.file />
<logback.configuration.file/>
</properties>
</profile>
</profiles>
Expand Down
21 changes: 21 additions & 0 deletions src/docs/1.3.0-release-notes.md
@@ -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.
15 changes: 8 additions & 7 deletions src/docs/confluence.txt
Expand Up @@ -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

Expand All @@ -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
Expand Down
69 changes: 69 additions & 0 deletions src/docs/jobdsl.md
@@ -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 5585a30

Please sign in to comment.