This post has already been read 2347 times!

I have talked about Database Change Management using Liquibase. Now, I will talk about the integration with Jenkins CI.

As you can see in the example of my previous post. In the pom.xml there are 3 profiles: update,tag and rollback which will be used by Jenkins. The profile approach will be useful in our integration.

I am going to use Cloudbees (PaaS)

1. First, you need to have an Cloudbees account.

2. Click on Databases and then click Add Database.

3. Create a liquibase_demo database.

4. Click on Builds, Jenkins dashboard will be display.

5. Create New Job.

6. Put a name, choose Build a free-style software project option and then click OK.

7. Now, let start to configure Jenkins’s job. You will be able to see the image below

8. Check This build is parameterized option. Then, click Add Parameter. Add the following parameters: driver, url, username, password, changeLogFile, tag and action.

driver, url, username, changeLogFile, tag are String Parameter

password is a Password Parameter.

action is a Choice Parameter with the following options: update, tag and rollback

9. Now, lets configure the Source Code Management. In this example, I have published the demo in GitHub.

10. Now, go to Build section, click on Add build step and choose Invoke top-level Maven targets. Add the maven’s goal and properties. Then, Save.

Maven Goal:

1
mvn install -P$action

Maven Properties:

1
2
3
4
5
6
7
8
liquibase.driver=$driver
liquibase.username=$username
liquibase.password=$password
liquibase.url=$url
liquibase.changeLogFile=$changeLogFile
liquibase.rollbackTag=$tag
liquibase.tag=$tag
liquibase.promptOnNonLocalDatabase=false

If you remember, we have created parameters at the beginning of this post which are reusing in this part using $ in order to do a dynamic job.

11. Finally, click Build with parameters, test your job and enjoy.

Avoid risks and say good bye to manual tasks. For that reason, I love automation!

Note: Liquibase can be used inside the java application using spring integration.

Leave a Reply

Post Navigation