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

Local settings.xml not picked up by Jenkins agent #63

Closed
dhoer opened this issue Jan 10, 2018 · 6 comments
Closed

Local settings.xml not picked up by Jenkins agent #63

dhoer opened this issue Jan 10, 2018 · 6 comments

Comments

@dhoer
Copy link

dhoer commented Jan 10, 2018

I'm using this image to build on jenkins:

  agent {
    docker {
      image 'maven:3-jdk-8-alpine'
      args '-v ${HOME}/.m2:/root/.m2'
    }
  }

The ${HOME}/.m2/settings.xml is there but is not getting picked up.

Using help:effective-settings, I get this:

Effective user-specific configuration settings:

<?xml version="1.0" encoding="UTF-8"?>
<!-- ====================================================================== -->
<!--                                                                        -->
<!-- Generated by Maven Help Plugin on 2018-01-10T09:13:42                  -->
<!-- See: http://maven.apache.org/plugins/maven-help-plugin/                -->
<!--                                                                        -->
<!-- ====================================================================== -->

<!-- ====================================================================== -->
<!--                                                                        -->
<!-- Effective Settings for '?' on '0c8a16058336'                           -->
<!--                                                                        -->
<!-- ====================================================================== -->

<settings xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">
  <localRepository xmlns="http://maven.apache.org/SETTINGS/1.1.0">/var/lib/jenkins/workspace/yah_master-W74OVL5IJZCMBOCWHOODNNWVE45JYUK5JBJSNCYBJ4O3HKTTZMQQ/?/.m2/repository</localRepository>
  <pluginGroups xmlns="http://maven.apache.org/SETTINGS/1.1.0">
    <pluginGroup>org.apache.maven.plugins</pluginGroup>
    <pluginGroup>org.codehaus.mojo</pluginGroup>
  </pluginGroups>
</settings>

I have also tried adding the settings.xml to /usr/share/maven/ref but get the same settings:

  agent {
    docker {
      image 'maven:3-jdk-8-alpine'
      args '-v ${HOME}/.m2/settings.xml:/usr/share/maven/ref/settings.xml -v ${HOME}/.m2:/root/.m2'
    }
  }

Is there a way to force the maven image to use ${HOME}/.m2/settings.xml?

@gonzalesraul
Copy link

The issue is related to the -u uid:gid that jenkins uses to run the container. As you may know the image you are running only has the user root created, so when jenkins pass its own uid and gid , there is no entry for the user and consequentially no $HOME declared for it.

If you only want to run the build independently of the user, you can use the follow as agent:

agent {
        docker {
            image 'maven:3-alpine'
            args '-v $HOME/.m2:/root/.m2:z -u root'
            reuseNode true
        }
}

A few notes:

  1. if you notice the volume I am using with the flag z, as I am going to build with root, I need to tell docker that this volume will be shared among another containers, and then preventing access denied from my jenkins container (running with the user jenkins not root)
  2. I tell jenkins to reuseNode, so any other stage using the same image, will be executing on the same container (it is just to speed up the provisioning time)

@dhoer
Copy link
Author

dhoer commented Jan 22, 2018

@gonzalesraul That works! Thank you for the help.

@dhoer dhoer changed the title Local settings.xml not picked up Local settings.xml not picked up by Jenkins agent Jan 22, 2018
@steinsag
Copy link

Is there any other workaround for it? Of course I want a new clean Maven container for each job run. And there must be a way to inject a custom settings.xml if container is not run as root.

In Jenkins, if the container is forced to run as root via

--user root:root

subsequent runs will fail as Jenkins is unable to delete generated directories.

Seems to be a long-time issue with this image, see: #14, #16, #18,

@gonzalesraul
Copy link

@steinsag yes, there is a few but I would suggest these below:

  1. Instead of use declarative docker agent to run on jenkins you could use docker cli (using sh commands), and then you pass the parameters on your own. As I stated earlier, the issue is that docker agent always will bind jenkins uid:gid, consequentially there is no user on the target container. If took control of that part, you could run as root, mount the workspace or whatever (use :z option on docker to share info amongst different contexts) and then get the result after all.

  2. The other option involves extending the maven image by adding jenkins user and jenkins agent, and then use that extended image as docker agent on your pipeline. That way you would be fine once the user will exists and jenkins has the agent to run as usual.

@carlossg
Copy link
Owner

I think this is an issue with jenkins, and somewhat fixed based on #16 (comment)

jenkinsci/docker-workflow-plugin#63 should have solved this without an image change.

@gonzalesraul
Copy link

@carlossg the issue resides on Jenkins for sure.

I think the root cause to getting these behaviors, resides on uid:gid binding on Jenkins to the container startup.

Your mention to jenkinsci/docker-workflow-plugin#63 only resolves the entrypoint option for scripted pipeline.

It still might not be on the maven container scope, but still a valid issue when used with docker-workflow-plugin

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

4 participants