1

I am running below command from Linux(Centos) terminal,

mvn --settings /home/centos/.m2/jenkins/liquibase-settings.xml -e resources:resources -Pdev -Dliquibase.promptOnNonLocalDatabase=false -Dliquibase.defaultSchemaName=MYDEV_SCHEMA liquibase:updateSQL liquibase:update -Dsettings.security=/home/centos/.m2/jenkins/liquibase-security-settings.xml -Dfile.encoding=UTF-8

Everything went fine.

Same thing when I run via Jenkins, getting below,

[ERROR] Failed to execute goal org.liquibase:liquibase-maven-plugin:4.2.0:updateSQL (default-cli) on project project-db: 
[ERROR] Error setting up or running Liquibase:
[ERROR] Validation Failed:
[ERROR]      16 change sets check sum
[ERROR]           db/changelog/ABCD.xml::1234-23::User1 was: 8:67913d9505606eeaaa4998fd594a8ccf but is now: 8:9d985650b579319df50f30732d66909c
[ERROR]           db/changelog/ABCD.xml::1234-78::User1 was: 8:3b3babd5d0712f846402af13ede528f7 but is now: 8:0214bf10acfd160fc6f7d709edab2f2e
[ERROR]           db/changelog/ABCD.xml::1234-142::User1 was: 8:5e3c8fc77fc87f0e9740c0bff717f579 but is now: 8:53094dd8c32ec71b8d76fdd71009c548
[ERROR]           db/changelog/ABCD.xml::1234-200::User1 was: 8:c40ec5c77f7b10961ee550edd756f51f but is now: 8:9bef09eb0681f7ea7bf827b6ac136433
[ERROR]           db/changelog/ABCD.xml::1234-923::User1 was: 8:747cbcbda155679dd2fc1bfcc40991c4 but is now: 8:68c8046c220b8d2eb46ed3ac07ebc2a2
[ERROR]           db/changelog/ABCD.xml::1234-952::User1 was: 8:ecaad2afacf6c61f18e08cb3e235292a but is now: 8:0f7f9087de5cc2e62a96a86988d07a9d
[ERROR]           db/changelog/ABCD.xml::1234-955::User1 was: 8:3ddd6fd25fb4a68accf50190b3ab6738 but is now: 8:8ebed2810bad45ace402f99a957a2c5a
[ERROR]           db/changelog/ABCD.xml::1234-957::User1 was: 8:cc6144775a784d10bc4523dccae02c2e but is now: 8:f0fb84fb3a677e760b5bbad3149e8a17
[ERROR]           db/changelog/ABCD.xml::1234-958::User1 was: 8:b0c71a212949df4863ce622e61315cee but is now: 8:9c6ea7b8f8cb3f6e65871085527fa4c5
[ERROR]           db/changelog/ABCD.xml::1234-960::User1 was: 8:b0966c55100b0a2daae7dd34b7d1849f but is now: 8:5db8b313d34612e1a0035caa73bfae2d
[ERROR]           db/changelog/ABCD.xml::1234-961::User1 was: 8:3e3b96c656362b5bed959428772efbdf but is now: 8:622c3530660fa51cfb806cc454736a8e
[ERROR]           db/changelog/ABCD.xml::1234-964::User1 was: 8:50e079098e7d2be9e1299d68717af265 but is now: 8:13ab1763f5f21e80dc5f7aa714916f01
[ERROR]           db/changelog/ABCD.xml::1234-971::User1 was: 8:fe000258281e834309f9454077e4935d but is now: 8:b238dad4489c9683a3e362820a0ba715
[ERROR]           db/changelog/ABCD.xml::1234-974::User1 was: 8:578a1f3510ac700373b40d83ffbfcdde but is now: 8:3eeb6e61dec24eac4148a6c66033e125
[ERROR]           db/changelog/ABCD.xml::100000011::User1 was: 8:5d0882f8413b6d1063ab023e7c4ec917 but is now: 8:e019e12a40add4536a128ba7b9b06f69
[ERROR]           db/changerequest/ABCD/ABCD.1_Base.xml::ABCD1-100000211::User1 was: 8:9ea4f4f4b5a2db0d1c7e439887e9129c but is now: 8:ebe390648144994233ecd6101e04380c
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.liquibase:liquibase-maven-plugin:4.2.0:updateSQL (default-cli) on project project-db: 

My Jenkins code,

dir("${liquibase_working_dir}"){
    configFileProvider([
        configFile(fileId: 'liquibase-settings.xml', variable: 'LIQUIBASE_SETTINGS'),
        configFile(fileId: 'liquibase-security-settings.xml', variable: 'LIQUIBASE_SECURITY_SETTINGS'),
    ]) {
        withMaven(maven:'maven', mavenSettingsFilePath: "${LIQUIBASE_SETTINGS}") {
            sh "mvn -e resources:resources liquibase:updateSQL liquibase:update -P${env_lowercase} \"-Dsettings.security=${LIQUIBASE_SECURITY_SETTINGS}\" -Dliquibase.promptOnNonLocalDatabase=false -Dliquibase.defaultSchemaName=${schema} -Dfile.encoding=UTF-8"
        }
    }
    sh "cp target/liquibase/migrate.sql target/liquibase/${env_lowercase}-${currentBuild.number}-${schema}-updates.sql"
}

I missed an important point, there are no commits to the liquibase repository.

karthikeayan
  • 4,291
  • 7
  • 37
  • 75

1 Answers1

5

When Liquibase reaches a changeset, it computes a checksum for it and stores it in the DATABASECHANGELOG table. The value of storing the checksum for Liquibase is to know if the changeset has been modified since it was run.

If the changeset has been changed since it was run, Liquibase will exit the migration with an error message like Validation failed: change set check sums <changeset identifer> was: <old checksum> but is now: <newchecksum>. This is because Liquibase cannot identify what was changed and the database may be in a state different than what the changelog is expecting.

To ignore this error on valid change made in changeset, there are below options:

1. clearCheckSums : clearCheckSums clears all checksums and nullifies the MD5SUM column of the DATABASECHANGELOG table so they will be re-computed on the next database update.Changesets that have been deployed will have their checksums re-computed, and pending changesets will be deployed. For more details about this approach, please visit this link

2. runOnChange attribute : The runOnChange attribute executes the change the first time it is seen and each time the changeset is modified. For more details about this approach, please visit this link

3. runAlways attribute : Executes the changeset on every run, even if it has been run before. To use this, set attribute runAlways = true in your changeset. Example as below:

<changeSet id="liquibase-0" author="liquibase" runAlways="true">
   <sqlFile relativeToChangelogFile="true" path="db/file.sql"/>
</changeSet>

4. The <validCheckSum> attribute : Add a element to the changeset. The text contents of the element should contain the old checksum from the error message.

5. Manual update of the DATABASECHANGELOG table : The first option is to manually update the DATABASECHANGELOG table so that the row with the corresponding id/author/filepath has a null value for the checksum. You would need to do this for all environments where the changeset has been deployed. The next time you run the Liquibase update command, it will update the checksum value to the new correct value.

Cheers!!

Rakhi Agrawal
  • 827
  • 7
  • 14
  • 4
    Nice answer explaining how to fix the issue currently. However, it does not explain why it fails on different environments and how to fix thiw permanently. These are only workarounds. – KHanusova Mar 30 '22 at 09:44