Liquibase executes changeset several times in single Maven build - maven

I am observing some strange Liquibase behavior when I run simple Maven project on TeamCity build agent.
Maven project structure:
changelogs/
databaseChangeLog.xml
pom.xml
Run command: mvn liquibase:update
databaseChangeLogs.xml contains next line: <includeAll path="changelogs/"/>
But build log contains duplication records:
liquibase: databaseChangeLog.xml: /home/teamcity/BuildAgent/work/28fe713da351c06d/changelogs/1.xml: ChangeSet /home/teamcity/BuildAgent/work/28fe713da351c06d/changelogs/1.xml ran successfully in 40ms
liquibase: databaseChangeLog.xml: Custom SQL executed
liquibase: databaseChangeLog.xml: changelogs/1.xml: ChangeSet changelogs/1.xml ran successfully in 36ms
So seems like Liquibase picked up changeset twice from different locations: from build agent's build folder and root of the project.
Does anybody meet the same issue?
Any ideas how to fix this?

Liquibase has kinda a design flaw which lays in considering at our first glance "identical" change sets as different. To bypass such a peculiarity you can use logicalFilePath attribute either on databaseChangeLog tag or on every changeSet tag. This one will add another level of identity, uniqueness to a your change set.

Related

Gradle liquibase plugin incremental build issue

I am using the liquibase plugin.
I want it to participate in incremental builds, so I defined:
tasks.withType(org.liquibase.gradle.LiquibaseTask) {
//for incremental builds
outputs.dirs("$rootDir/liquibase/src/main/resources", 'build/generated')
}
Everything works fine, except that after I do a ./gradlew clean (which deletes the build/generated directory), the task is still considered UP-TO-DATE, so it doesn't execute again the migrations.
Full context of the issue: I am using the docker avast plugin, I am spinning up a PostgreSQL database, I run the liquibase update (db is empty, so all the migrations should run), then I use jooq codegen to generate Java classes based on the schema (they are generated in build/generated). The other tasks (composeUp, generateJooq) have the same outputs.dirs gradle configuration, but after I execute ./gradlew clean they are re-executed.
I fixed it by creating a dummy file in each task, define it as an output file and use that as an input for the next task.

Jenkins build step is unable to delete directory

Until recently everything worked fine with our build process in Jenkins. We got a quite big project with many modules and a complicated dependency structure.
Suddenly, the build fails with error messages like the following:
Failed to execute goal certain-plugin:109:certainEar(certainEar)
on project app: certain plugin: Can't explode ear file
'app-SNAPSHOT.ear': Error, directory can't be deleted
The maven command that gets executed in the build pipeline and results in the error message is the following:
mvn -B -U package -DskipTests
A temporary workaround is manually deleting the affected directory. Previously I had a similar problem with the deletion of an ear, there it was possible to exclude the affected ear from this build step as it was not required there. Afterwards I got the error message mentioned above.
Now I found a (kind of) final solution: Adding clean to the targets of the maven command:
mvn -B -U clean package -DskipTests
Now the building step works fine. But why the heck does this happen? Do you have any hints what could lead to this behavior? I'm quite clueless to say the least.
Somehow this could have something to do with the extraction of an ear out of our big app ear. Shortly after we finished this and merged it into our master branch those errors began to arise. As I was not involved in this work it's hard to track down what happened there exactly and what could lead to this behavior. In parallel I will investigate what the colleagues did there. Hints from you what the reasons could be will certainly help to track this down.
I found nothing similar to this error messages online that helped me in any way.
Your solution "mvn clean" indicates me that your job is executing on a jenkins workspace that contains the execution of the previous job. I would recommend to always start your job by clearing what's in the workspace. In freestyle job, under section Source Code Management you can add the behavior
Wipe out repository & force clone
in pipelines, you would use checkout step
checkout([$class: 'GitSCM',
extensions: scm.extensions + [[$class: 'WipeWorkspace']] + [[$class: 'PruneStaleBranch']],
userRemoteConfigs: [[
url: '<git_url>'
]]
])
there are other ways to clean a workspace in a pipeline like cleanWS and deleteDir. Do prefer the checkout WipeWorkspace plugin

Sonar exclusion properties is not picking up during scan

I'm trying to run sonar scanner from jenkins by cloning the source code from the Github repo.
Usecase: while running the sonar scanner I don't want to include some of the project directories to be a part of the scan.
To which I've added the following properties in order:
Sonar.projectkey= Sonar.projectversion= Sonar.projectname= Sonar.sources= X, x/y, x/z Sonar.exclusions= x/a/**
After running the sonar scanning with the above results, I came to know that the scan is still picking up the code from the x/a/** directories. Please suggest any inputs If I'm missing anything here.
it should be:
sonar.exclusions=x/a/**
without blank:
Sonar.exclusions= x/a/**
if you want to run on command line, it should be :
-Dsonar.exclusions=x/a/**

Bamboo build error: How to properly clean bamboo caches?

The problem:
Bamboo executes old unit tests that don't exist my current develop branch which causes a build error.
The situation that causes this problem:
After a big refactoring process of my maven java project, where I basically moved, modified and renamed every file, I committed my changes to my remote repository.
That triggered my bamboo build plan, to start the build process.
The git code checkout seems to work, but the next step, running the unit tests, fails!
Looking in the log file I see that an old, no more existing java Unit test class gets executed and of course fails because of NullPointerExceptions.
Things I tried to fix this problem
A. Remove caches in the Administration section
I went to Bamboo->Administration->Repository Settings and selected
the cache of my project and deleted it.
I started the build plan again
BUILD ERROR ! Same problem
B. Delete the cache directory in the file system
Start a RDP session on the bamboo server
stop bamboo
go to D:\bamboo-home_64\xml-data\build-dir_git-repositories-cache
delete all files in this folder
start bamboo
start the build plan again
BUILD ERROR! same problem
Meta info
bamboo version: 6.1.0 build 60103 - 18 Jul 17
I don't know what I can do to fix this..
There's Clean working directory task. Add it as first task to your Job and see if it solves the issue.

set configuration properties in sonar

Maybe, this question is silly but I'm very new. I try to search without luck.
I got two errors when building maven project with sonar:
No information about coverage per test.
Although I had test code and these testing classes cover the code.
The global property 'sonar.doxygen.deploymentPath' is not set. Set it in SONAR and run another analysis.
I dont know it should be set where in sonar server. I set in web.xml or sonar-server.properties but it does not work.
Thanks.
About the first warning message this is not an error but a warning : since Sonar 3.5 this is possible to get the code coverage relating to each unit test. Here the message just says that this feature is not activated which is expected by default. Nevertheless I do agree that this warning message can be misleading.
About the second error message, I don't know the doxygen plugin but the message seems to be pretty clear : the sonar.doxygen.deploymentPath property has not be defined. See the plugin documentation : http://docs.codehaus.org/display/SONAR/Doxygen+Plugin.
Two things:
There is no war folder anymore since the sonarqube has given up tomcat support
The doxygen plugin is not implemented to upload the files in to the sonarqube server &/ installation, which means it only can be done by referencing the path inside your installation, e.g.:
run "mvn install sonar:sonar" in your project "/root/test.example.sonar.com"
in sonarqube set the cfg-key "sonar.doxygen.deploymentPath" the value: "/root/sonarqube-4.1.1/web/" and the cfg-key "sonar.doxygen.deploymentUrl" the value: "http://:9000"
have fun with your doxygen
Remember that the plugin will only be run through your mvn cmd, refreshing the page only will not do the job, you will have to analyse again after each cfg set :/
Check the file system and folder permission

Resources