Skip to content
Permalink
Browse files
Merge branch 'feature/JENKINS-40707-pipeline-support' into develop
  • Loading branch information
prospero238 committed Jan 4, 2017
2 parents 7c865b8 + 2611651 commit 8a5d9961760781775e5778373233790192e80d1e
Show file tree
Hide file tree
Showing 39 changed files with 1,255 additions and 267 deletions.
38 pom.xml
@@ -1,11 +1,12 @@
<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>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>2.9</version>
<relativePath />
<version>1.596.1</version>
<relativePath/>
</parent>
<artifactId>liquibase-runner</artifactId>
<version>1.2.0-SNAPSHOT</version>
@@ -49,13 +50,39 @@
</pluginRepositories>
<properties>
<jenkins.version>1.596.1</jenkins.version>
<workflow.version>1.7</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>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-aggregator</artifactId>
<version>${workflow.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-step-api</artifactId>
<version>${workflow.version}</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-support</artifactId>
<version>${workflow.version}</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
@@ -171,10 +198,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>
@@ -192,6 +219,5 @@
</dependency>
</dependencies>
</profile>

</profiles>
</project>
@@ -1,7 +1,11 @@
# 1.2.0 Release notes

*Important* This version now uses the [Credentials Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Credentials+Plugin) to manage usernames and passwords to connect to the database. If you were using username & password configuration in the previous version of this plugin, it will be necessary to redefine them using the credentials configuration.
**Important**
This version now uses the [Credentials Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Credentials+Plugin) to manage usernames and passwords to connect to the database. If you were using username & password configuration in the previous version of this plugin, it will be necessary to redefine them using the credentials configuration.

# Changes

* [Credentials Integration](https://issues.jenkins-ci.org/browse/JENKINS-33401)
* [JENKINS-40707 Pipeline Support](https://issues.jenkins-ci.org/browse/JENKINS-40707)
* [JENKINS-33401 Credentials Integration](https://issues.jenkins-ci.org/browse/JENKINS-33401)


@@ -43,6 +43,51 @@ 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()

Available parameters:
testRollbacks
tagOnSuccessfulBuild
dropAll.

Roll back operations may be done thusly:

liquibasaeRollback()

Available parameters:

rollbackCount
rollbackToTag
rollbackToDate
rollbackLastHours




Common to each operation are the following parameters:
databaseEngine: Can be set to "MySQL", "PostgreSQL", "Derby", "H2", or "Hypersonic". Providing this value
eliminates the need to supply driverClassname.
credentialsId: The ID of the Jenkins credentials to use when the database requires username & password
changeLogFile: Path to the change log file
url: Database JDBC URL
See liquibase execution for an explaination for these configuration elements:
defaultSchemaName
contexts
liquibasePropertiesPath
classpath
driverClassname
labels
changeLogParameters
basePath

Supplying only "changeLogFile" will cause the buildstep to use an H2 in-memory database.


h2. Usage Tips

* If you'd like to have only new changesets evaluated, consider using an H2 JDBC url like
@@ -55,6 +100,7 @@ h3. Version History
h4. Version 1.2.0

* Credentials integration
* [JENKINS-40707|https://issues.jenkins-ci.org/browse/JENKINS-40707] Pipeline Support

h4. Version 1.1.0 (Aug 25, 2016)

@@ -3,6 +3,7 @@
import hudson.EnvVars;
import hudson.FilePath;
import hudson.model.AbstractBuild;
import hudson.model.Run;

import java.io.IOException;
import java.io.InputStreamReader;
@@ -35,28 +36,36 @@ public class PropertiesAssembler {
* <li>Values from properties file described by {@link AbstractLiquibaseBuilder#liquibasePropertiesPath}</li>
* <li>Values on the {@link AbstractLiquibaseBuilder} itself.</li>
* </ul>
* Furthermore, any token expressions found are replaced with values found in the passed environment.
* Furthermore, any token expressions found are replaced with values found in the passed environment IF build
* is an AbstractBuild.
*
* @param liquibaseBuilder
* @param build
* @param environment
* @param workspace
* @return
*/
public static Properties createLiquibaseProperties(AbstractLiquibaseBuilder liquibaseBuilder,
AbstractBuild<?, ?> build, EnvVars environment)
Run<?, ?> build, EnvVars environment, FilePath workspace)
throws IOException, InterruptedException {
Properties properties = new Properties();
assembleDefaults(properties);
String propertiesPath = resolvePropertiesPath(liquibaseBuilder, environment);
assembleFromPropertiesFile(properties, propertiesPath, build);

String propertiesPath;
if (build instanceof AbstractBuild) {
propertiesPath = hudson.Util.replaceMacro(liquibaseBuilder.getLiquibasePropertiesPath(), environment);
} else {
propertiesPath = liquibaseBuilder.getLiquibasePropertiesPath();
}
assembleFromPropertiesFile(properties, propertiesPath, workspace);

assembleFromProjectConfiguration(liquibaseBuilder, properties, environment, build);
return properties;
}

protected static void assembleFromProjectConfiguration(AbstractLiquibaseBuilder liquibaseBuilder,
Properties properties,
EnvVars environment, AbstractBuild<?, ?> build)
EnvVars environment, Run<?, ?> build)
throws IOException, InterruptedException {


@@ -67,38 +76,37 @@ protected static void assembleFromProjectConfiguration(AbstractLiquibaseBuilder
Lists.<DomainRequirement>newArrayList());

if (credentialById!=null) {
addPropertyIfDefined(properties, LiquibaseProperty.USERNAME, credentialById.getUsername(), environment);
addPropertyIfDefined(properties, LiquibaseProperty.PASSWORD, credentialById.getPassword().getPlainText(), environment);
addPropertyIfDefined(properties, LiquibaseProperty.USERNAME, credentialById.getUsername(), environment, build);
addPropertyIfDefined(properties, LiquibaseProperty.PASSWORD, credentialById.getPassword().getPlainText(), environment,
build);
}
}



addPropertyIfDefined(properties, LiquibaseProperty.CHANGELOG_FILE, liquibaseBuilder.getChangeLogFile(),
environment);
environment, build);

addPropertyIfDefined(properties, LiquibaseProperty.CLASSPATH, liquibaseBuilder.getClasspath(), environment);
addPropertyIfDefined(properties, LiquibaseProperty.CLASSPATH, liquibaseBuilder.getClasspath(), environment,
build);
addPropertyIfDefined(properties, LiquibaseProperty.DEFAULT_SCHEMA_NAME, liquibaseBuilder.getDefaultSchemaName(),
environment);
addPropertyIfDefined(properties, LiquibaseProperty.URL, liquibaseBuilder.getUrl(), environment);
environment, build);
addPropertyIfDefined(properties, LiquibaseProperty.URL, liquibaseBuilder.getUrl(), environment, build);
addPropertyIfDefined(properties, LiquibaseProperty.CHANGELOG_FILE, liquibaseBuilder.getChangeLogFile(),
environment);
addPropertyIfDefined(properties, LiquibaseProperty.LABELS, liquibaseBuilder.getLabels(), environment);
addPropertyIfDefined(properties, LiquibaseProperty.CONTEXTS, liquibaseBuilder.getContexts(), environment);
resolveDatabaseDriver(liquibaseBuilder, properties, environment);
environment, build);
addPropertyIfDefined(properties, LiquibaseProperty.LABELS, liquibaseBuilder.getLabels(), environment, build);
addPropertyIfDefined(properties, LiquibaseProperty.CONTEXTS, liquibaseBuilder.getContexts(), environment, build);
resolveDatabaseDriver(liquibaseBuilder, properties, environment, build);
}

private static void resolveDatabaseDriver(AbstractLiquibaseBuilder liquibaseBuilder,
Properties properties,
EnvVars environment) {
EnvVars environment, Run<?, ?> build) {


boolean useIncludedDriver = useIncludedDriver(liquibaseBuilder);
if (useIncludedDriver) {
PropertiesAssembler.setDriverFromDBEngine(liquibaseBuilder, properties);
} else {
addPropertyIfDefined(properties, LiquibaseProperty.DRIVER, liquibaseBuilder.getDriverClassname(),
environment);
environment, build);
}
}

@@ -111,9 +119,9 @@ private static boolean useIncludedDriver(AbstractLiquibaseBuilder liquibaseBuild

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

if (!Strings.isNullOrEmpty(liquibasePropertiesPath)) {
FilePath workspace = build.getWorkspace();
if (workspace != null) {
InputStreamReader streamReader = null;
try {
@@ -149,17 +157,18 @@ private static void setProperty(Properties properties, LiquibaseProperty liquiba

protected static void addPropertyIfDefined(Properties properties,
LiquibaseProperty liquibaseProperty,
String value, EnvVars environment) {
String value, EnvVars environment, Run<?, ?> build) {
if (!Strings.isNullOrEmpty(value)) {
String resolvedValue = hudson.Util.replaceMacro(value, environment);
String resolvedValue;
if (build instanceof AbstractBuild) {
resolvedValue = hudson.Util.replaceMacro(value, environment);
} else {
resolvedValue = value;
}
properties.setProperty(liquibaseProperty.propertyName(), resolvedValue);
}
}

private static String resolvePropertiesPath(AbstractLiquibaseBuilder liquibaseBuilder, EnvVars environment) {
return hudson.Util.replaceMacro(liquibaseBuilder.getLiquibasePropertiesPath(), environment);
}

public static void setDriverFromDBEngine(AbstractLiquibaseBuilder liquibaseBuilder, Properties properties) {
if (!Strings.isNullOrEmpty(liquibaseBuilder.getDatabaseEngine())) {
for (IncludedDatabaseDriver includedDatabaseDriver : liquibaseBuilder.getDrivers()) {

0 comments on commit 8a5d996

Please sign in to comment.