Can Jenkins work the same way as the GitLab Runner + Docker executor :

  1. From the image to expand the container.
  2. Inside the container, clone the git repository, execute arbitrary commands.
  3. Select the artifacts and save them outside the container, collapse the container (finish its work).

Question : I need step-by-step instructions on how to set up Jenkins to complete the above three steps.

Found Docker Plugin . It seems that he knows how to deploy a Jenkins slave in a docker, connect it to the master and dispose of it after use. This option does not exactly suit me, because I need to drag Java and other unnecessary things into the build environment. The basic jenkins-slave image weighs 100 times as much as the alpine , it is generally beyond reasonable.

 docker images REPOSITORY ... SIZE alpine ... 3.97 MB evarga/jenkins-slave ... 368 MB 

I also found the Docker build step plugin. One of the features is "create new container from image". Maybe I need exactly this, but I do not understand how to do points 2 and 3.

  • Either pull a full slave, or manually (exec / bash script in cmd) perform all actions with the repository and deal with the keys to access the repository. Otherwise, I'm afraid, no way. - etki
  • Although there seems to be an opportunity to use SSH-slaves, on which jenkins will install an agent himself, but there will still need java +, time will be spent directly on installation - etki
  • @etki i. inside the container write the key in .ssh/ , put git, clone the repository? - Nick Volynkin
  • @etki Ok, maybe I succumbed to the XY problem. Are there any simpler ways to perform Jenkins tasks in a pure phoenix environment? - Nick Volynkin
  • Yes, plus all sorts of trivia such as the struggle with the unfilled known_hosts. I do not know of other methods, but this does not mean that they are not. I myself decided in my time that it’s better to have one giant image with everything you can (rvm, nvm, phpbrew, jabba + directly installed basic versions of the software itself + all sorts of phantomjs) than go the other way. - etki

1 answer 1

In Jenkins, you can run the bash / batch command, for bash it will be something like this:

 docker run -it -d my_image # запускам image в detached моде docker exec $(docker ps -a -q --filter ancestor=my_image) bash -c "cd your_path; your_command" # запускаем Вашу команду в контейнере. list=$(docker exec $(docker ps -a -q --filter ancestor=my_image) bash -c 'ls /path/to/artifacts/inside/container') # создаем список артефактов, которые мы будем вытаскивать из контенера for i in $list; do docker cp $(docker ps -a -q --filter ancestor=my_image):$i ./path/to/outside container ; done # вытаскиваем артефакты согласно списку for i in $(docker ps -a -q --filter ancestor=my_image); do docker rm $(docker stop $i); done # удалям контейнеры, если они работают 
  • I will not have time to check today, but I will award the reward - the competition ends. - Nick Volynkin
  • Thanks, in the end, I managed GitLab CI, but this solution will still come in handy soon. - Nick Volynkin
  • glad to help - nick_gabpe