Code Monkey home page Code Monkey logo

Comments (6)

gonzalesraul avatar gonzalesraul commented on May 18, 2024 9

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)

from docker-maven.

dhoer avatar dhoer commented on May 18, 2024

@gonzalesraul That works! Thank you for the help.

from docker-maven.

steinsag avatar steinsag commented on May 18, 2024

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,

from docker-maven.

gonzalesraul avatar gonzalesraul commented on May 18, 2024

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

from docker-maven.

carlossg avatar carlossg commented on May 18, 2024

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.

from docker-maven.

gonzalesraul avatar gonzalesraul commented on May 18, 2024

@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

from docker-maven.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.