/dev/blah

things i want to remember, things i want to share

Développeur Python et adepte Linux depuis 2005, Core développeur Kivy, passionné par beaucoup trop de choses.
Profil Github gpg signature bitcoin address

Entries tagged “jenkins”

Jenkins + docker slave

written by tshirtman, on 1/2/15 4:44 PM.

Seems there is a lot of info about this already, but it still took me literally days to get what i wanted, so here is a quick recap, in case you are having issues with this too.

  • you probably don’t need the docker plugin for jenkins, i spent way too much time trying to understand how it worked, and it didn’t do what i want in the end.
  • you can easily execute docker commands in a shell script by adding jenkins to the docker group, no need to add a tcp socket in docker configuration to use the rest api, simple commands just work.
  • you can simply mount the workspace into the docker container (-v $WORKSPACE:/home/user/workspace -w /home/user/workspace) and pass the right command to build it.

gotchas:

  • you’ll probably want the user in the docker instance to have the same uid as the jenkins user doing the setup, just get it from /etc/passwd and use the –uid option to give the same one to your user
  • docker doesn’t set the HOME env var to the user one, unless the image you are using has been fixed for that, so pass -e HOME=/home/user
  • you don’t want “-t” to docker run, because that will make the build success immediatly without waiting for the end of your commands
  • to avoid docker containers piling up, just add –rm so the container gets destroyed at the end of the job, the result should be in the workspace anyway.

So in the end, i just did a freestyle or multiconfiguration project, set up the scm (git), and put a shell script build step, along the lines of

USER=jenkins
RM=--rm # comment out to keep the instance around for debugging
#TTY=-t #useful to debug
IMAGE=jenkins-docker
COMMAND="buildozer android debug"
HOME=/home/$USER

docker run $RM $TTY -i -v $WORKSPACE:$HOME/build -u $USER -w $HOME/build -e HOME=$HOME $IMAGE $COMMAND

bonus point: you can totally run that out of jenkins to test it manually (just set WORKSPACE to a copy of your project), which can ease the preparation of your image and avoid cluttering jenkins with unneeded failed builds.

Tags

#FIXME 3G absurd ad_sense alterway aléatoire android animation anonymity atheism bach backlog bash bitcoins blog blogging boldness book books boulot bricolage bépo C canvas captcha captures carte SD censure christianity chroot CI CLI cli cloudwatt code colors comfort zone command line community company life conferences contest copwatch copwatchnord-idf core-devs cours ct705 culture deb debian debug deformation dehors dessin dev distribute distribution docker débutant déploiement développement ebooks eeepad eeepc effect ego empty en escher event firefly flappy bird flask fosdem foss fr fun game garden gdb geek culture git github goals graphics grrr gödel hack hackathon hacked hacking health hooks i3 images IMAP inspirational install isync java jenkins jeu jeu video jinja2 jni keyboard keynav kivy kv lame learning lib libre life linux lol macosx magnet mail mailing-list mails maths mbsync meetings memory leak mesh meta mint mirroir MIT module motivational mouse museomix mutt nexus7 no-mouse notmuch nottoomuch offlineimap onycroit opencourseware osc packaging paris passphrase password patch pentacatyl people perte de données ping pip planning plugin positioning pr procrastination programmation progress project projet property proudhon proxy psf publisher/consumer pull-down pygame pyjnius pypi python pythonar qtile raid rapsberry pi reading recorder references release religion responsive review reviews réseau réseaux sociaux résurection salon screenshots script self service shows shutil shyness sizing solib sortie sousous!!! spam spritz stash status systeme système templating terminal texture texture coordinates Thomas Paine thread thème tiling time time management. tip tips tools transformer tutorial tv twitter typematrix typing ubuntu ubuntu-fr ultimate-smash-friends unity update upload images useless usf utils value VDM video vie/mort vim virtualenv visite widget windows wm wmii work workflow workflow. zine études