Skip to content
Permalink
Browse files
JENKINS-40707
creation of update pipeline class, allowing "liquibaseUpdate" to be used in pipeline script
  • Loading branch information
prospero238 committed Dec 30, 2016
1 parent f87003e commit 16705668dfa6a9a3839ffff403a22fcd1b202074
Show file tree
Hide file tree
Showing 7 changed files with 356 additions and 91 deletions.
27 pom.xml
@@ -5,7 +5,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>2.9</version>
<version>1.596.1</version>
<relativePath/>
</parent>
<artifactId>liquibase-runner</artifactId>
@@ -50,13 +50,34 @@
</pluginRepositories>
<properties>
<jenkins.version>1.596.1</jenkins.version>
<workflow.version>1.4</workflow.version>
</properties>
<dependencies>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>credentials</artifactId>
<version>1.16.1</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-step-api</artifactId>
<version>${workflow.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-cps</artifactId>
<version>${workflow.version}</version>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-job</artifactId>
<version>${workflow.version}</version>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
@@ -172,10 +193,10 @@
</build>
<profiles>
<profile>
<id>jenkins_2_7_2</id>
<id>jenkins_2_x</id>
<!-- for testing against a later version of jenkins -->
<properties>
<jenkins.version>2.7.2</jenkins.version>
<jenkins.version>2.38</jenkins.version>
</properties>
</profile>
<profile>
@@ -0,0 +1,198 @@
package org.jenkinsci.plugins.liquibase.workflow;

import hudson.Extension;

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;
protected boolean testRollbacks;
private boolean dropAll;
protected boolean tagOnSuccessfulBuild;

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


@Extension
public static final class DescriptorImpl extends AbstractStepDescriptorImpl {

public DescriptorImpl() {
super(LiquibaseUpdateExecution.class);
}

@Override
public String getFunctionName() {
return "liquibaseUpdate";
}

@Nonnull
@Override
public String getDisplayName() {
return "Evaluate liquibase changesets";
}
}

@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;
}

@DataBoundSetter
public void setDropAll(boolean dropAll) {
this.dropAll = dropAll;
}

@DataBoundSetter
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;
}

public boolean isDropAll() {
return dropAll;
}

public boolean isTagOnSuccessfulBuild() {
return tagOnSuccessfulBuild;
}
}
@@ -0,0 +1,62 @@
package org.jenkinsci.plugins.liquibase.workflow;

import hudson.EnvVars;
import hudson.FilePath;
import hudson.Launcher;
import hudson.model.Run;
import hudson.model.TaskListener;

import org.jenkinsci.plugins.liquibase.evaluator.ChangesetEvaluator;
import org.jenkinsci.plugins.workflow.steps.AbstractSynchronousStepExecution;
import org.jenkinsci.plugins.workflow.steps.StepContextParameter;

import com.google.inject.Inject;

public class LiquibaseUpdateExecution extends AbstractSynchronousStepExecution<Void> {

@Inject
private transient LiquibaseUpdateBuildStep step;

@StepContextParameter
private transient TaskListener listener;

@StepContextParameter
private transient Launcher launcher;

@StepContextParameter
private transient Run<?, ?> run;

@StepContextParameter
private transient FilePath ws;

@StepContextParameter
private transient EnvVars envVars;


@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());


changesetEvaluator.setTestRollbacks(step.isTestRollbacks());
changesetEvaluator.setDropAll(step.isDropAll());
changesetEvaluator.setTagOnSuccessfulBuild(step.isTagOnSuccessfulBuild());


changesetEvaluator.perform(run, ws, launcher, listener);
return null;

}
}

0 comments on commit 1670566

Please sign in to comment.