cloudogu / ces-build-lib

Jenkins pipeline shared library adding features for Maven, Gradle, Docker, SonarQube, Git and others
GNU Affero General Public License v3.0
75 stars 49 forks source link

MavenInDocker: Does not work when pom is in subfolder #49

Open sklein94 opened 4 years ago

sklein94 commented 4 years ago

I had a problem building a maven project which was using the maven scm plugin. I was using the MavenInDocker-class to build the project.

The maven project is inside of a subfolder in the main project. So i was using the dir block in my Jenkinsfile. The problem is, that in this case only the current dir was mounted into the maven-docker-container which caused the build to fail because the .git-folder in the parent folder is required when using the scm-plugin.

To bypass this i executed the maven build in the base directory (to make sure everything is mounted inside docker) and passed the path to the pom.xml into the additionalArgs of the maven object.

Can you please make sure that the whole project is mounted into the maven-in-docker-container? Maybe there is also another way, but i dont have an idea.

schnatterer commented 4 years ago

@sklein94 thanks for reporting. I stumbled upon this issue before. Not with maven but with dir and docker. My solution was to explicitly mount the whole Jenkins workspace into the container.

docker.image('someImg')
  .inside("-v ${env.WORKSPACE}:${env.WORKSPACE}") {
     //...
 }

We could apply this to MavenInDocker in general. Do you think this would solve your issue?

You can try it out in a replay. Just set the following

String runArgs = "-v ${env.WORKSPACE}:${env.WORKSPACE} "

Here: https://github.com/cloudogu/ces-build-lib/blob/70ea143e3c899948591f2fd44b4d6b00f9c7b978/src/com/cloudogu/ces/cesbuildlib/MavenInDockerBase.groovy#L30-L43

sklein94 commented 4 years ago

@schnatterer Thank you for your response. Yes, this sounds good and should solve my issue!