I previously told you how to install Jenkins on server. Now, I would like to share his article on installing Jenkins and Jenkins-slave. I for my example, I’m using Docker + docker-compose to pick up everything you need. Of course, it’s not a good way to do occasionaliy server. Nevertheless, — on my Mac everything works. Moreover, I set this miracle is not for PROD and local labs. To more pororno to explore Jenkins. I would like to say, guys, if you will choose between CI/CD — Jenkins do not take (IMHO). There are mad other cool bodies. I want many of them to try, and of course — write an article in the form of notes.
Installing Jenkins on Unix/Linux
Working with Jenkins-CLI in Unix/Linux
Installing Docker in Debian, s
Installing Docker RedHat’s
Install Docker-compose in Unix/Linux
Installing Jenkins on Unix/Linux
As I said earlier, I’ll use Docker to install Jenkins. OS I use is Mac OS X. skagul, who cares, you’re running in Docker. But really — Docker works a little differently on different Unix/Linux OS. Had a little dance with a tambourine to envy all of the magic on the Mac.
My docker-compose.yml file looks like the following:
--- version: '3.5' services: networks: image: networks networks-ce:latest container_name: networks hostname: networks.local labels: com.example.description: "Accounting webapp" ports: - "443:443" - "80:80" - "2222:22" dns: - 10.17.0.3 - 22.214.171.124 - 126.96.36.199 volumes: "/usr/local/networks/config:/etc/networks:rw" - "/usr/local networks/logs:/var/log/networks:rw" "/usr/local/networks/data:/var/opt/networks:rw" extra_hosts: jenkins_local_docker: 188.8.131.52 socat_container: 184.108.40.206 restart: always environment: - GITLAB_OMNIBUS_CONFIG="external_url 'http://gitlab.local:80'; gitlab_rails['gitlab_shell_ssh_port']=2222; gitlab_rails['lfs_enabled'] = true;" networks: network0: ipv4_address: 220.127.116.11 healthcheck: test: ["CMD", "curl", "-f", "http://gitlab.local"] interval: 1m30s timeout: 10s retries: 3 start_period: 5m jenkins: image: jenkins/jenkins:latest container_name: jenkins hostname: jenkins.local ports: - "8080:8080" - "50000:50000" dns: - 10.17.0.3 - 18.104.22.168 - 22.214.171.124 volumes: "/usr/local/jenkins/data_2:/var/jenkins_home:rw" - "/var/run/docker.sock:/var/run/docker.sock:rw" "/usr/local/bin/docker:/bin/docker" extra_hosts: gitlab_local_docker: 126.96.36.199 socat_container: 188.8.131.52 restart: always privileged: true environment: - DOCKER_HOST=tcp://socat:2375 links: - socat depends_on: - networks networks: network0: ipv4_address: 184.108.40.206 pid: host socat: image: bpack/socat container_name: socat hostname: socat_container restart: "always" privileged: true ports: - "2375:2375" dns: - 10.17.0.3 - 220.127.116.11 - 18.104.22.168 command: "TCP4-LISTEN:2375,fork,reuseaddr unix-connect:/var/run/docker.sock" volumes: - "/var/run/docker.sock:/var/run/docker.sock" networks: network0: ipv4_address: 22.214.171.124 #volumes: #docker_socket: #driver_opts: # type: none # device: "/var/run/docker.sock" # o: bind networks: network0: ipam: driver: default config: - subnet: 126.96.36.199/24
Who works with Docker-kompos, he will be able to read this file and understand what it is. But if someone knows, let me tell you what you should focus on. And so:
I start the service 3 container — networks, jenkins (master) and socat. Networks — control system for Git code repositories. data configuration was made universal and make it work in any place and on Unix/Linux systems. If something does not work, you should consider the DNS (in this field written DNS-s which serve rezolvam in the Docker container. Sometimes it is appropriate, when at work or at home uses its own DNS, and the rest are blocked).
You can use the article to check which DNS-s is used:
Working with DNS in Unix/Linux
PS: this field should ONLY use 3 DNS RECORDS, no more! Otherwise, they simply won’t work and can break the container(s).
A look at “socat” conainer and ask why he is here at all fell? So, here he is forwarding data from port (2375) on Unix socket (/var/run/docker.sock). And again, can get questions, and why?
Yes, the fact that Docker progeny “failed” gash “docker_opts”/”hosts” variable in the Docker for Mac OS X. This variable actually performs the same actions, but native sposobom. It looks like this (with Linux):
DOCKER_OPTS="-H tcp://127.0.0.1:2375 -H unix:///var/run/docker.sock"
Ie, this command has to be done in the config of Docker, or you can start the daemon as follows:
$ sudo docker -H tcp://127.0.0.1:2375 -H unix:///var/run/docker.sock -d
I do not understand why it was impossible to add such support for the Mac, but workaround found and it works. In General, such a miracle must work on Linux, but I haven’t checked. If someone is interested, please check and write in the comments the result.
The whole thing, I spent about 7 hours and I was not very clear why. But in the Internet I found an example of my disaster. I took the idea and tried it — kostylenko, but what can you do!
The most interesting that I in its implementation zayuzat “Docker in Docker”, ie bounced Docker with Mac OS X on Docker host jenkins. Otherwise , I don’t know how it should work. If someone knows — tell ?
In fact, networks + jenkins — ready to use. Let’s move on to setting up jenkins-slave.
Install a Jenkins-Slave on Unix/Linux
You should put a Docker Plugin plugin. I was put — Docker Slaves Plugin the plugin, but did not understand how it works. I’ll show you what plugins I have in Jenkins, maybe someone will be useful, but for starters, download the CLI for Jenkins:
$ cd ~ && curl 'localhost:8080/jnlpJars/jenkins-cli.jar' > ~/jenkins-cli.jar
My installed plugins:
After the plugins supplied, open Jenkins and go:
“Manage Jenkins” -> “Configure System” and look for the field “Cloud”:
Click on “Docker Cloud Details” to enter the required data:
Ask the name, I — Docker. In the “Docker Host URI” set host and port which he uses Docker. I have “tcp://188.8.131.52:2375”. For some reason, do not ride the use of hostname from Sakata in this case. Might fix it later, or in extreme cases, you can leave as is, because this lab serves as an example. It is worth noting, if you use authorization to the Docker host, you should fill in the “Server credentials”. If you click on “Advanced”, you’ll get a list of additional parameters that can be zapaliti too:
Click on “Test connection” to test connection (to verify that connexin works as it should).
Go ahead, click on the “DOCKER AGENT TEMPLATES…” I brought to mind:
Filled box and label as I want. In the “Docker image” I ordered Jenkins-Slave image that I took from the official Docker-registry “jenkinsci/slave”. Also, you need to fill in all required fields (credencial, additional options).
The first build (gob) on Jenkins-e
Create a project to fit your needs. Then, create a “Pipeline” project, for example:
Test pipeline for Java projec
Click on “OK” and now will create all necessary.
Find the “Run the build inside Docker containers” and put the checkbox. In the “Docker Image” put our way, I — “jenkinsci/jnlp-slave:latest”. Also, you can specify “Advanced settings” options and set using memory. All I have is:
Go ahead, find the “Pipeline” tab and fill it to suit your needs. I have all the above and has the form:
Ie I zayuzat your hitlab server. It has a repository with the project. Also, added a connection to galabo. In fact, everything is ready, you can click on “SAVE”!
At the top left, click on “Build Now” and see what happened!
If you open “Manage Jenkins” -> “Manage Nodes” will appear jenkins-slave:
It is seen that raised a slave and run the job. You can open it and see the execution status:
I think that’s all for now, the article “Installing Jenkins and Jenkins-slave Unix/Linux” is completed.