Maven inside Docker’d build agents
I previously posted about how you can use Jenkins in a Docker container, and then use Jenkins Swarm to create build agents automatically? There was an issue with the build agent which caused Maven to download dependencies from localhost. You’d see something like
+ mvn package [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building MyApp 1.0.0-SNAPSHOT [INFO] ------------------------------------------------------------------------ Downloading: http://localhost:8082/archiva/repository/all/org/apache/maven/plugins/maven-resources-plugin/2.5/maven-resources-plugin-2.5.pom [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 1.274s [INFO] Finished at: Wed May 13 17:13:28 UTC 2015 [INFO] Final Memory: 5M/107M [INFO] ------------------------------------------------------------------------ [ERROR] Plugin org.apache.maven.plugins:maven-resources-plugin:2.5 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-resources-plugin:jar:2.5: Could not transfer artifact org.apache.maven.plugins:maven-resources-plugin:pom:2.5 from/to maestro-mirror (http://localhost:8082/archiva/repository/all): Connection to http://localhost:8082 refused: Connection refused -> [Help 1] |
[INFO] ————————————————————————
[INFO] BUILD FAILURE
[INFO] ————————————————————————
[INFO] Total time: 1.274s
[INFO] Finished at: Wed May 13 17:13:28 UTC 2015
[INFO] Final Memory: 5M/107M
[INFO] ————————————————————————
[ERROR] Plugin org.apache.maven.plugins:maven-resources-plugin:2.5 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-resources-plugin:jar:2.5: Could not transfer artifact org.apache.maven.plugins:maven-resources-plugin:pom:2.5 from/to maestro-mirror (http://localhost:8082/archiva/repository/all): Connection to http://localhost:8082 refused: Connection refused -> [Help 1]
I tracked it down to the build agent I recommended in the article.
Originally, I simply converted my builds to use SBT which works out of the box. But I know people like using Maven, so I spent some time investigating. I ran a bash prompt inside a maestrodev/build-agent container to see where it was pointing to localhost.
$ docker run -it maestrodev/build-agent /bin/bash [root@3047ef38684a /]# cd /var/local/maestro-agent/ [root@3047ef38684a ~]# ls -al total 1036 drwx------ 4 maestro_agent maestro_agent 4096 Feb 13 15:43 . drwxr-xr-x 3 root root 4096 Feb 13 15:40 .. -rwxr-xr-x 1 maestro_agent maestro_agent 307 Feb 13 15:40 ant.xml -rw-r--r-- 1 maestro_agent maestro_agent 18 Oct 16 2014 .bash_logout -rw-r--r-- 1 maestro_agent maestro_agent 176 Oct 16 2014 .bash_profile -rw-r--r-- 1 maestro_agent maestro_agent 124 Oct 16 2014 .bashrc drwxr-xr-x 2 maestro_agent maestro_agent 4096 Feb 13 15:40 .gem -rw-r--r-- 1 maestro_agent maestro_agent 61 Feb 13 15:43 .gitconfig drwx------ 2 maestro_agent root 4096 Feb 13 15:43 .m2 -rw------- 1 maestro_agent root 76 Feb 13 15:40 .puppetforge.yml -rw-r--r-- 1 maestro_agent maestro_agent 1019622 Sep 30 2014 swarm-client-1.17-jar-with-dependencies.jar [root@3047ef38684a ~]# cat .m2/settings.xml <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> <!-- ... snipped unrelated stuff out ... --> <mirrors> <mirror> <id>maestro-mirror</id> <url>http://localhost:8082/archiva/repository/all</url> <mirrorOf>external:*</mirrorOf> </mirror> </mirrors> <!-- ... snipped unrelated stuff out ... --> </settings> |
<!– … snipped unrelated stuff out … –>
</settings>
This is the configuration file which tells Maven to use localhost to download artifacts.
I built a new Docker image based on this image, but I removed this file. Maven successfully builds projects. If you’re using Maven, then I recommend you use this one – andrewgortonuk/dockerjenkinswithgitbuildagent.
0 Comments on “Maven inside Docker’d build agents”