2
votes

I am using the docker-custom-build-environment-plugin (https://wiki.jenkins-ci.org/display/JENKINS/CloudBees+Docker+Custom+Build+Environment+Plugin) to build a maven job inside a docker container.

I have done the following setup as shown in this image: enter image description here

This is the result in the console log:

$ docker inspect maven:3.3.3-jdk-8
[{
    "Architecture": "amd64",
    "Author": "",
    "Comment": "",
    "Config": {
        "AttachStderr": false,
        "AttachStdin": false,
        "AttachStdout": false,
        "Cmd": [
            "mvn"
        ],
        "CpuShares": 0,
        "Cpuset": "",
        "Domainname": "",
        "Entrypoint": null,
        "Env": [
            "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
            "LANG=C.UTF-8",
            "JAVA_VERSION=8u66",
            "JAVA_DEBIAN_VERSION=8u66-b17-1~bpo8+1",
            "CA_CERTIFICATES_JAVA_VERSION=20140324",
            "MAVEN_VERSION=3.3.3",
            "MAVEN_HOME=/usr/share/maven"
        ],
        "ExposedPorts": null,
        "Hostname": "",
        "Image": "b7928b8a133284ec65b4790aa3d013bd3e266ea3e257c6a6d0254b9708a133e8",
        "Labels": {},
        "MacAddress": "",
        "Memory": 0,
        "MemorySwap": 0,
        "NetworkDisabled": false,
        "OnBuild": [],
        "OpenStdin": false,
        "PortSpecs": null,
        "StdinOnce": false,
        "Tty": false,
        "User": "",
        "Volumes": null,
        "WorkingDir": ""
    },
    "Container": "7393955c8b148c5d2b6da0a5fdf5623aa699ce2ed9ab1f43c2ba79913654bf0b",
    "ContainerConfig": {
        "AttachStderr": false,
        "AttachStdin": false,
        "AttachStdout": false,
        "Cmd": [
            "/bin/sh",
            "-c",
            "#(nop) CMD [\"mvn\"]"
        ],
        "CpuShares": 0,
        "Cpuset": "",
        "Domainname": "",
        "Entrypoint": null,
        "Env": [
            "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
            "LANG=C.UTF-8",
            "JAVA_VERSION=8u66",
            "JAVA_DEBIAN_VERSION=8u66-b17-1~bpo8+1",
            "CA_CERTIFICATES_JAVA_VERSION=20140324",
            "MAVEN_VERSION=3.3.3",
            "MAVEN_HOME=/usr/share/maven"
        ],
        "ExposedPorts": null,
        "Hostname": "",
        "Image": "b7928b8a133284ec65b4790aa3d013bd3e266ea3e257c6a6d0254b9708a133e8",
        "Labels": {},
        "MacAddress": "",
        "Memory": 0,
        "MemorySwap": 0,
        "NetworkDisabled": false,
        "OnBuild": [],
        "OpenStdin": false,
        "PortSpecs": null,
        "StdinOnce": false,
        "Tty": false,
        "User": "",
        "Volumes": null,
        "WorkingDir": ""
    },
    "Created": "2015-11-11T08:06:10.345733061Z",
    "DockerVersion": "1.9.0",
    "Id": "642c36d39ed754e55c15a382531bc60591154b7280356708dca833d346891415",
    "Os": "linux",
    "Parent": "b7928b8a133284ec65b4790aa3d013bd3e266ea3e257c6a6d0254b9708a133e8",
    "Size": 0,
    "VirtualSize": 651375578
}
]
$ docker run --rm --entrypoint /bin/true maven:3.3.3-jdk-8
$ docker run --tty --detach --workdir /example/apphome/jenkins/workspace/IntegrationTesting-Components --volume /tmp:/tmp:rw --volume /example/apphome/jenkins:/example/apphome/jenkins:rw --net bridge --add-host dockerhost:172.17.42.1 --env BUILD_DISPLAY_NAME=#1733 --env BUILD_ID=1733 --env BUILD_NUMBER=1733 --env BUILD_TAG=jenkins-IntegrationTesting-Components-1733 --env BUILD_URL=http://tools.example.com/jenkins/job/IntegrationTesting-Components/1733/ --env buildInfoConfig.propertiesFile=/tmp/buildInfo6572943319531125678.properties --env CLASSPATH= --env EXECUTOR_NUMBER=1 --env extractor.used=true --env GIT_BRANCH=origin/feature/java8 --env GIT_COMMIT=8569f85875d85c7181dcf9bf261819a1c55279cf --env GIT_PREVIOUS_COMMIT=8569f85875d85c7181dcf9bf261819a1c55279cf --env GIT_PREVIOUS_SUCCESSFUL_COMMIT=49617fb1a913a30c7111f60d2ace4f9aca0d8aa9 --env GIT_URL=ssh://[email protected]/int/components.git --env HUDSON_HOME=/example/apphome/jenkins --env HUDSON_SERVER_COOKIE=cb467bbe36d08ed4 --env HUDSON_URL=http://tools.example.com/jenkins/ --env JAVA_HOME=/usr/lib/jvm/java-1.7.0 --env JENKINS_HOME=/example/apphome/jenkins --env JENKINS_SERVER_COOKIE=cb467bbe36d08ed4 --env JENKINS_URL=http://tools.example.com/jenkins/ --env JOB_NAME=IntegrationTesting-Components --env JOB_URL=http://tools.example.com/jenkins/job/IntegrationTesting-Components/ --env M2_HOME=/example/apps/apache-maven-3.0.3 --env MAVEN_HOME=/example/apps/apache-maven-3.0.3 --env "MAVEN_OPTS=-D-Xms256m -Xmx1024m -XX:MaxPermSize=512m -Dm3plugin.lib=D:\data\Jenkins\plugins\artifactory\WEB-INF\lib" --env "NODE_LABELS=deployqueue docker linux maven jenkins-server" --env NODE_NAME=jenkins-server --env PATH+JDK=/usr/lib/jvm/java-1.7.0/bin --env PATH+MAVEN=/example/apps/apache-maven-3.0.3/bin --env POM_ARTIFACTID=components --env "POM_DISPLAYNAME=Integration Testing Components" --env POM_GROUPID=com.example.integrationtesting --env POM_PACKAGING=jar --env POM_VERSION=java8-SNAPSHOT --env WORKSPACE=/example/apphome/jenkins/workspace/IntegrationTesting-Components maven:3.3.3-jdk-8 /bin/cat
Docker container 66994ba8669ba42203e0ced67fcf16674bceaab2d0477e04ed92466eb05858e1 started to host the build
Parsing POMs
maven3-agent.jar already up to date
maven3-interceptor.jar already up to date
maven3-interceptor-commons.jar already up to date
$ docker exec --tty 66994ba8669ba42203e0ced67fcf16674bceaab2d0477e04ed92466eb05858e1 env
[IntegrationTesting-Components] $ docker exec --tty --user 501216: 66994ba8669ba42203e0ced67fcf16674bceaab2d0477e04ed92466eb05858e1 env BUILD_DISPLAY_NAME=#1733 BUILD_ID=1733 BUILD_NUMBER=1733 BUILD_TAG=jenkins-IntegrationTesting-Components-1733 BUILD_URL=http://tools.example.com/jenkins/job/IntegrationTesting-Components/1733/ buildInfoConfig.propertiesFile=/tmp/buildInfo6572943319531125678.properties CA_CERTIFICATES_JAVA_VERSION=20140324 CLASSPATH= EXECUTOR_NUMBER=1 extractor.used=true GIT_BRANCH=origin/feature/java8 GIT_COMMIT=8569f85875d85c7181dcf9bf261819a1c55279cf GIT_PREVIOUS_COMMIT=8569f85875d85c7181dcf9bf261819a1c55279cf GIT_PREVIOUS_SUCCESSFUL_COMMIT=49617fb1a913a30c7111f60d2ace4f9aca0d8aa9 GIT_URL=ssh://[email protected]/int/components.git HOME=/root HOSTNAME=66994ba8669b HUDSON_HOME=/example/apphome/jenkins HUDSON_SERVER_COOKIE=cb467bbe36d08ed4 HUDSON_URL=http://tools.example.com/jenkins/ JAVA_DEBIAN_VERSION=8u66-b17-1~bpo8+1 JAVA_HOME=/usr/lib/jvm/java-1.7.0 JAVA_VERSION=8u66 JENKINS_HOME=/example/apphome/jenkins JENKINS_SERVER_COOKIE=cb467bbe36d08ed4 JENKINS_URL=http://tools.example.com/jenkins/ JOB_NAME=IntegrationTesting-Components JOB_URL=http://tools.example.com/jenkins/job/IntegrationTesting-Components/ LANG=C.UTF-8 M2_HOME=/example/apps/apache-maven-3.0.3 MAVEN_HOME=/example/apps/apache-maven-3.0.3 "MAVEN_OPTS=-D-Xms256m -Xmx1024m -XX:MaxPermSize=512m -Dm3plugin.lib=D:\data\Jenkins\plugins\artifactory\WEB-INF\lib" MAVEN_VERSION=3.3.3 "NODE_LABELS=deployqueue docker linux maven jenkins-server" NODE_NAME=jenkins-server PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin PATH+JDK=/usr/lib/jvm/java-1.7.0/bin PATH+MAVEN=/example/apps/apache-maven-3.0.3/bin POM_ARTIFACTID=components "POM_DISPLAYNAME=Integration Testing Components" POM_GROUPID=com.example.integrationtesting POM_PACKAGING=jar POM_VERSION=java8-SNAPSHOT TERM=xterm WORKSPACE=/example/apphome/jenkins/workspace/IntegrationTesting-Components /usr/lib/jvm/java-1.7.0/bin/java -D-Xms256m -Xmx1024m -XX:MaxPermSize=512m -Dm3plugin.lib=D:\data\Jenkins\plugins\artifactory\WEB-INF\lib -Djava.awt.headless=true -cp /example/apphome/jenkins/maven3-agent.jar:/example/apps/apache-maven-3.0.3/boot/plexus-classworlds-2.4.jar org.jvnet.hudson.maven3.agent.Maven3Main /example/apps/apache-maven-3.0.3 /example/apphome/jenkins/slave.jar /example/apphome/jenkins/maven3-interceptor.jar /example/apphome/jenkins/maven3-interceptor-commons.jar 44922
flag provided but not defined: --user
See 'docker exec --help'.
run PrePostClean
running on jenkins-server
clean on master
Stopping Docker container after build completion
$ docker kill 66994ba8669ba42203e0ced67fcf16674bceaab2d0477e04ed92466eb05858e1
66994ba8669ba42203e0ced67fcf16674bceaab2d0477e04ed92466eb05858e1
$ docker rm --force 66994ba8669ba42203e0ced67fcf16674bceaab2d0477e04ed92466eb05858e1
66994ba8669ba42203e0ced67fcf16674bceaab2d0477e04ed92466eb05858e1
ERROR: Failed to launch Maven. Exit code = 2

Any idea what i am doing wrong?

1

1 Answers

0
votes

The advice from https://www.cloudbees.com/blog/templating-jenkins-build-environments-docker-containers on using their plugin is to base your slaves off evarga/jenkins-slave

The Dockerfile that you've based it off has some key differences such as the creation of the creation of the jenkins user and starting the sshd daemon. So if you're going to start off from your own image, base it off the evarga image first.