Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sklein94 opened this issue Nov 12, 2020 · 2 comments
Open

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

sklein94 opened this issue Nov 12, 2020 · 2 comments

Comments

@sklein94
Copy link
Contributor

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
Copy link
Member

schnatterer commented Nov 12, 2020

@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:

String createDockerRunArgs() {
String runArgs = ""
if (useLocalRepoFromJenkins) {
// If Jenkin's local maven repo does not exist, make sure it is created by the user that runs the build.
// Otherwise, if not existing, this folder is create as root, which denies permission to jenkins
script.sh returnStatus: true, script: 'mkdir -p $HOME/.m2'
// Mount Jenkin's local maven repo as local maven repo within the container
runArgs += " -v ${script.env.HOME}/.m2:${script.pwd()}/.m2"
}
return runArgs
}

@sklein94
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants