First, environmental preparation

1. Cluster introduction

Jenkins is a popular continuous integration tool with powerful functions. It supports building clusters to improve the construction speed of multiple projects. The mode is mainly slave mode, and the master will assign tasks to each slave node for concurrent construction, so as to improve the speed

2. Environment preparation

  • Server: Prepare two servers, one as master and one as slave. Set SERVER A as master and server B as slave
  • Server system: Linux(I’m using Ubuntu here)
  • Jenkins version: 2.287, Jenkins only needs to be installed in the master, the deployment tutorial can be referred to: juejin.cn/post/695020…

3. Prepare the slave node environment

Depending on which source code management tool you are using git or SVN, you will need to install the right tools, as well as the environment required for the project you may be building, for example. NET Core projects need to install the.NET Core SDK, and JAVA projects need to install the JAVA environment. Jenkins does not need to be installed on the slave node.

Here is the environment Jenkins needs to prepare for the Slave node to construct the Python automated test task:

  • python3
  • jdk >= 8
  • Google chrome (Note version)
  • Chromedriver (the same version as Google chrome)
  • The package environment required by Python can be generated locally and executed from the nodepip3 install -r requirements.txt
  • Allure (Requires Allure to generate test report)

Ii. Jenkins creates a new node

1. Establish a connection between primary and secondary nodes (create credentials)

  • Master Generates a key. Master run the following command:

    #The generated key is saved in ~/. SSH /id_rsa
    ssh-keygen
    #The key is sent to the slave node. The login password of the slave node is entered as user root
    ssh-copy-id slave_ip
    Copy the code
  • Jenkins creates credentials

    Jenkins System Management ==> Credential Management ==> New == “Add global credential

2. Jenkins creates a node

  • Creating a Node System management ==> Management node => Create a node

    Click OK to access node information configuration:

    Click OK and return to the node management interface. Now you can see the node we just created, but it is still offline.

    If manual authentication is selected when a new node is created, click Trust SSH Host Key on the left after logging in to the node to manually verify the Key

    After the key verification is successful, click start agent, if no error is reported, the node agent is successful, go back to node management, you can see slave1 node is online.

3. Select the node to perform the task and configure node properties

1. Select a label node to execute the task

  • Free style task configuration

    In task configuration, select the running node of the restricted project and enter the label name

  • Pipeline configuration

    pipeline {
        agent { node { label 'linux_python_test'}}}Copy the code

2. Configure the node Allure tool

Node management => Click the node to be configured. => Node properties => Select Tool Locations => Add Allure Command