Step by step, this article teaches you how to use jenkins+docker to implement the master-slave mode

♥ Foreword

The jenkins master-slave mode must be familiar to everyone. During the learning process, everyone built a jenkins environment locally for the convenience of learning, and then realized it through javaweb. Everyone seems to be very interested in implementing the master-slave mode under docker. Today I will tell you how to play through this article, I hope it will be helpful to you.

1. Environmental preparation

  1. Prepare a Linux server (cloud server, self-built Linux server can be)

  2. Install docker on Linux server

  3. Pull a jenkins image down, and then start a jenkins container

  4. Pull down this image jenkins/ssh-slave in docker (the image provided by jenkins is specially used as a master-slave image)

  5. OK preparations are done

If you want to learn automated testing, here I recommend a set of videos for you. This video can be said to be the first interface automation testing tutorial on the entire network at station B. At the same time, the number of online users has reached 1,000, and there are notes to collect and various Lu Dashen Technical Exchange: 798478386     

[Updated] The most detailed collection of practical tutorials for automated testing of Python interfaces taught by station B (the latest version of actual combat)_哔哩哔哩_bilibili [Updated] The most detailed collection of practical tutorials for automated testing of Python interfaces taught by station B (actual combat) The latest version) has a total of 200 videos, including: 1. [Interface Automation] The current market situation of software testing and the ability standards of testers. , 2. [Interface Automation] Fully skilled in the Requests library and the underlying method call logic, 3. [Interface Automation] interface automation combat and the application of regular expressions and JsonPath extractors, etc. For more exciting videos, please pay attention to the UP account. https://www.bilibili.com/video/BV17p4y1B77x/?spm_id_from=333.337&vd_source=488d25e59e6c5b111f7a1a1a16ecbe9a

2. Ready to start work
The first step: docker enables remote access, you need to open port 2375, this port should be opened carefully (I use centos)
  1. Open the docker.service file
    VIM /usr/lib/systemd/system/docker.service

  2. Add the following content under [Service] in the docker.service file
    [Service]
    ExecStart=
    ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock

  3. Restart the docker service and let docker re-read the configuration file
    systemctl daemon-reload
    systemctl restart docker

  4. Verify, check the docker process, if the docker daemon process is already listening to the tcp port of 2375, even if the port 2375 is successfully opened

    picture

  5. Further verification, access the docker host through other machines
    sudo docker -H tcp://139.129.130.123:2375 images
    The above command is equivalent to directly executing the docker images command on the docker host, and it can return correctly, indicating that there is no problem

Step 2: Download the official website image (by the way, don’t forget it)
  1. docker pull jenkins/ssh-slave

Step 3: Create a new image with python3 environment based on jenkins/ssh-slave
  1. Create a dockerfile directory

  2. Put the python package file that the project execution depends on into the dockerfile directory (how to generate the dependent file will not be written, by default you are a master)

requests==2.24.0
openpyxl
ddt
pytest
selenium
pymysql
pyyaml==5.3.1
faker
jsonpath
BeautifulReport
unittestreport
rsa
pytest-html
Appium-Python-Client
  1. Create a file named sources.list (the name cannot be changed and must be this name), add the following content
    in the jenkins/ssh-slave mirror /etc/apt/ directory
    deb http://mirrors.163.com/debian/ buster main non-free contrib
    deb http://mirrors.163.com/debian/ buster-updates main non-free contrib
    deb http://mirrors.163.com/debian/ buster-backports main non-free contrib
    deb-src http://mirrors.163.com/debian/ buster main non-free contrib
    deb-src http://mirrors.163.com/debian/ buster-updates main non-free contrib
    deb-src http://mirrors. 163.com/debian/ buster-backports main non-free contrib
    deb http://mirrors.163.com/debian-security/ buster/updates main non-free contrib
    deb-src http://mirrors.163.com/ debian-security/buster/updates main non-free contrib
    Sources.list Description: The official jenkins/ssh-slave does not have python, and you need to install python to update its installation package. At this time, if you use its default mirror source, it will be very slow, so we change it to a faster one. Source, just overwrite its original file, here you need to modify it according to your own version number, mine is the buster version, of course, it should be the same as mine after you download it.

  2. write Dockerfile

FROM jenkins/ssh-slave:latest
USER root
WORKDIR /app
ADD requirements.txt  /app
ADD sources.list /etc/apt/
RUN echo export JAVA_TOOL_OPTIONS="-Dfile.encoding=UTF-8" >> /etc/profile
RUN apt-get -y update  && apt-get -y install python3 && apt-get -y install python3-pip && pip3 install -r requirements.txt -i https://pypi.douban.com/simple
  1. Execute the image build command
    docker build -t jenkins/ssh-slave:v2.0 .

Step 4: Configure the jenkins slave node
  1. Go to the node configuration page
    manage jenkins ---> Slave Node (node ​​management) ---> ConfigureClouds

picture

You will see the following page

 

  1. Click Add a new cloud and select docker from the drop-down list. After clicking, you will come to the following page

    picture

  2. Click on Docker Cloud details to configure, the page is as follows

    picture

  3. Click on Docker Agent templates, you will see the following page

    picture

  4. Click on the advanced options below

    picture

  5. The specific configuration of advanced options is as shown in the figure below

    picture

    picture

  6. Remember to save after the configuration is complete, it is best to save while configuring to develop a good habit.

Step 5: Bind docker slave to your jenkins task
  1. Create a new task, select Freestyle Project

    picture

  2. Restrict the project to run the node, select the newly created node (Labels)

    picture

  3. Configure Git

    picture

  4. Configure shell commands

    picture

  5. Configuration Test Report

picture

picture

picture

Step Six: Build Your Project
  1. After starting the build, you will see the following figure in your build queue

picture

2. After the build is complete, click on your project, and there will be a build record when you come here. Click it to see the build log

picture

3. View test report

picture

4. The test report is as follows

picture

 

Guess you like

Origin blog.csdn.net/m0_73409141/article/details/132233434