Skip to content

Commit

Permalink
JENKINS-40707
Browse files Browse the repository at this point in the history
provided build steps for liquibase operations.
  • Loading branch information
prospero238 committed Jan 2, 2017
1 parent 4aa8744 commit fb8f1cc
Show file tree
Hide file tree
Showing 16 changed files with 440 additions and 205 deletions.
1 change: 0 additions & 1 deletion pom.xml
Expand Up @@ -219,6 +219,5 @@
</dependency>
</dependencies>
</profile>

</profiles>
</project>
18 changes: 18 additions & 0 deletions src/docs/confluence.txt
Expand Up @@ -43,6 +43,24 @@ The rollback build step invokes liquibase's "rollback" operation on the target d

This build step is intended for use when you're deploying to a real environment, and the need arises to undo a previous liquibase update.

h2. Pipeline Support

Both the plugin's update and rollback operations are available to pipline scripts. To evaulate changesets, the syntax
is as follows:

liquibaseUpdate()

Parameters include testRollbacks, tagOnSuccessfulBuild, and dropAll.

Roll back operations may be done thusly:

liquibasaeRollback()

Parameters include:

Common to each operation are the following parameters:


h2. Usage Tips

* If you'd like to have only new changesets evaluated, consider using an H2 JDBC url like
Expand Down
Expand Up @@ -57,7 +57,7 @@ public static Properties createLiquibaseProperties(AbstractLiquibaseBuilder liqu
} else {
propertiesPath = liquibaseBuilder.getLiquibasePropertiesPath();
}
assembleFromPropertiesFile(properties, propertiesPath, build, workspace);
assembleFromPropertiesFile(properties, propertiesPath, workspace);

assembleFromProjectConfiguration(liquibaseBuilder, properties, environment, build);
return properties;
Expand Down Expand Up @@ -119,7 +119,7 @@ private static boolean useIncludedDriver(AbstractLiquibaseBuilder liquibaseBuild

private static void assembleFromPropertiesFile(Properties properties,
String liquibasePropertiesPath,
Run<?, ?> build, FilePath workspace) {
FilePath workspace) {

if (!Strings.isNullOrEmpty(liquibasePropertiesPath)) {
if (workspace != null) {
Expand Down
@@ -0,0 +1,140 @@
package org.jenkinsci.plugins.liquibase.workflow;

import javax.annotation.CheckForNull;
import javax.annotation.Nullable;

import org.jenkinsci.plugins.workflow.steps.AbstractStepImpl;
import org.kohsuke.stapler.DataBoundSetter;

public class AbstractLiquibaseStep extends AbstractStepImpl {
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 String changeLogParameters;
private String basePath;

@CheckForNull
private String credentialsId;

public AbstractLiquibaseStep(
String changeLogFile) {
this.changeLogFile = changeLogFile;
}

@DataBoundSetter
public void setDatabaseEngine(String databaseEngine) {
this.databaseEngine = databaseEngine;
}

@DataBoundSetter
public void setChangeLogFile(String changeLogFile) {
this.changeLogFile = changeLogFile;
}

@DataBoundSetter
public void setUrl(String url) {
this.url = url;
}

@DataBoundSetter
public void setDefaultSchemaName(String defaultSchemaName) {
this.defaultSchemaName = defaultSchemaName;
}

@DataBoundSetter
public void setContexts(String contexts) {
this.contexts = contexts;
}

@DataBoundSetter
public void setLiquibasePropertiesPath(String liquibasePropertiesPath) {
this.liquibasePropertiesPath = liquibasePropertiesPath;
}

@DataBoundSetter
public void setClasspath(String classpath) {
this.classpath = classpath;
}

@DataBoundSetter
public void setDriverClassname(String driverClassname) {
this.driverClassname = driverClassname;
}

@DataBoundSetter
public void setLabels(String labels) {
this.labels = labels;
}

@DataBoundSetter
public void setChangeLogParameters(String changeLogParameters) {
this.changeLogParameters = changeLogParameters;
}

@DataBoundSetter
public void setBasePath(String basePath) {
this.basePath = basePath;
}

@DataBoundSetter
public void setCredentialsId(String credentialsId) {
this.credentialsId = credentialsId;
}

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 String getChangeLogParameters() {
return changeLogParameters;
}

public String getBasePath() {
return basePath;
}

@Nullable
public String getCredentialsId() {
return credentialsId;
}


}
Expand Up @@ -5,31 +5,18 @@
import javax.annotation.Nonnull;

import org.jenkinsci.plugins.workflow.steps.AbstractStepDescriptorImpl;
import org.jenkinsci.plugins.workflow.steps.AbstractStepImpl;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;

public class LiquibaseUpdateBuildStep extends AbstractStepImpl {
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 String changeLogParameters;
private String basePath;
private Boolean useIncludedDriver;
private String credentialsId;
public class LiquibaseUpdateBuildStep extends AbstractLiquibaseStep {

protected boolean testRollbacks;
private boolean dropAll;
protected boolean tagOnSuccessfulBuild;

@DataBoundConstructor
public LiquibaseUpdateBuildStep(String changeLogFile) {
this.changeLogFile = changeLogFile;
super(changeLogFile);
}


Expand All @@ -52,71 +39,6 @@ public String getDisplayName() {
}
}

@DataBoundSetter
public void setDatabaseEngine(String databaseEngine) {
this.databaseEngine = databaseEngine;
}

@DataBoundSetter
public void setChangeLogFile(String changeLogFile) {
this.changeLogFile = changeLogFile;
}

@DataBoundSetter
public void setUrl(String url) {
this.url = url;
}

@DataBoundSetter
public void setDefaultSchemaName(String defaultSchemaName) {
this.defaultSchemaName = defaultSchemaName;
}

@DataBoundSetter
public void setContexts(String contexts) {
this.contexts = contexts;
}

@DataBoundSetter
public void setLiquibasePropertiesPath(String liquibasePropertiesPath) {
this.liquibasePropertiesPath = liquibasePropertiesPath;
}

@DataBoundSetter
public void setClasspath(String classpath) {
this.classpath = classpath;
}

@DataBoundSetter
public void setDriverClassname(String driverClassname) {
this.driverClassname = driverClassname;
}

@DataBoundSetter
public void setLabels(String labels) {
this.labels = labels;
}

@DataBoundSetter
public void setChangeLogParameters(String changeLogParameters) {
this.changeLogParameters = changeLogParameters;
}

@DataBoundSetter
public void setBasePath(String basePath) {
this.basePath = basePath;
}

@DataBoundSetter
public void setUseIncludedDriver(Boolean useIncludedDriver) {
this.useIncludedDriver = useIncludedDriver;
}

@DataBoundSetter
public void setCredentialsId(String credentialsId) {
this.credentialsId = credentialsId;
}

@DataBoundSetter
public void setTestRollbacks(boolean testRollbacks) {
this.testRollbacks = testRollbacks;
Expand All @@ -132,58 +54,6 @@ public void setTagOnSuccessfulBuild(boolean tagOnSuccessfulBuild) {
this.tagOnSuccessfulBuild = tagOnSuccessfulBuild;
}

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 String getChangeLogParameters() {
return changeLogParameters;
}

public String getBasePath() {
return basePath;
}

public Boolean getUseIncludedDriver() {
return useIncludedDriver;
}

public String getCredentialsId() {
return credentialsId;
}

public boolean isTestRollbacks() {
return testRollbacks;
}
Expand Down
Expand Up @@ -36,19 +36,7 @@ public class LiquibaseUpdateExecution extends AbstractSynchronousStepExecution<V
@Override
protected Void run() throws Exception {
ChangesetEvaluator changesetEvaluator = new ChangesetEvaluator();
changesetEvaluator.setDatabaseEngine(step.getDatabaseEngine());
changesetEvaluator.setChangeLogFile(step.getChangeLogFile());
changesetEvaluator.setUrl(step.getUrl());
changesetEvaluator.setDefaultSchemaName(step.getDefaultSchemaName());
changesetEvaluator.setContexts(step.getContexts());
changesetEvaluator.setLiquibasePropertiesPath(step.getLiquibasePropertiesPath());
changesetEvaluator.setClasspath(step.getClasspath());
changesetEvaluator.setDriverClassname(step.getDriverClassname());
changesetEvaluator.setLabels(step.getLabels());
changesetEvaluator.setChangeLogParameters(step.getChangeLogParameters());
changesetEvaluator.setBasePath(step.getBasePath());
changesetEvaluator.setUseIncludedDriver(step.getUseIncludedDriver());

LiquibaseWorkflowUtil.setCommonConfiguration(changesetEvaluator, step);

changesetEvaluator.setTestRollbacks(step.isTestRollbacks());
changesetEvaluator.setDropAll(step.isDropAll());
Expand All @@ -59,4 +47,5 @@ protected Void run() throws Exception {
return null;

}

}

0 comments on commit fb8f1cc

Please sign in to comment.