Continuous integration: Jenkins installation and deployment on Windows

1. The meaning of continuous integration

Continuous integration, as the name implies, is to keep things in software development in one place for management and processing without interruption, including code base maintenance, test environment construction, test script running, test result report sending, etc. Through continuous integration tools to gather these things together and follow certain steps for automated management, which is very similar to the automated testing framework, except that the former framework is not limited to testing, but runs through all aspects of the entire project. The benefit of continuous integration is to reduce repetitive work and automatically execute these tasks through continuous integration tools to improve the efficiency of the entire project.

Two, continuous integration tool: Jenkins

1. Tool features

1. Java-based continuous integration tool
2. Free and open source
3. Multi-platform compatibility: windows, Linux, OS
4. Visual management: After starting the tool, you can open it directly in the browser
5. Simple configuration: all functions can be configured Plug-in completion
6. Complete functional plug-ins: Plug-ins are the core of Jenkins. The platform tools themselves only provide a basic framework, and then install and use plug-ins to complete specific things and functions. You can also write plug-ins and upload them for use, which is extremely extensible.

2. Tool installation and activation (Windows)

①Start the Jenkins service

1. Prepare a test machine configured with java environment
2. Visit the official website to download the Windows version of Jenkins: https://jenkins.io/zh/download/
3. After the download is successful, jenkins.msidouble-click a file to install
4. Run the cmd window in the installation directory. java -jar jenkins.war
Note: If you start to report an error, Jenkins defaults The port number is 8080. When 8080 is occupied, it will fail to start. At this time, modify the command: java -jar jenkins.war --httpPort=9000modify the port number to 9000.
5. If the following prompt appears, it means the startup is successful.

6. You can write a batch to start under Windows. The code is as follows :

set jenkins_home=F:\jenkins
cd /d %jenkins_hom%
java -jar %jenkins_hom%\jenkins.war --httpPort=9000

②Visit the Jenkins management page

1. Open the browser and visit: localhost:9000
2. Unlock Jenkins: enter the administrator password (acquisition method: get it from the path file on the page prompt, and the cmd window that starts is printed)
3. Customize Jenkins: select the recommended plug-in, It will be installed automatically. Waiting for all the plug-ins to appear, it means the installation is complete (the plug-ins can be installed and updated in the plug-in management later)
4. Initialize the administrator account
5. Instance configuration: Jenkins url: localhost is changed to the IP address
6. Start Use Jenkins

3. Build tasks

①New task

1. Enter the task name
2. Select the task type template (generally choose the first free style, because the template is highly flexible)

②Configuration task

1. Discard old builds: Discard old builds , as the name implies, automatically delete the build, because each build needs to save the results and logs and other things, and they will be saved separately, which will occupy the system space over time, so you need to follow certain rules. Cleanup, the default is not checked, and all build records are kept. After checking, it can be automatically deleted according to the rules of time and number of builds.

2. Close the build: Generally, it will not be checked, unless there are special circumstances that need to be closed during a certain period of time, check this option.
3. Quiet period: the waiting time before the build, in seconds.
4. The number of SCM checkout retries : Re-execute the specified number of times when the code library fails to obtain the code, if it still fails after the specified number of times, the execution will stop.
5. Source code management:

  • 默认: None, that is, no code tools are used. This situation is mainly used for tasks that do not need to modify the code, such as regular execution of certain script tasks or automated test tasks
  • git/Subversion:After checking, add the corresponding account and manage the code

6. Build triggers: All build scripts must meet the conditions set by the trigger before they can be executed, which means that subsequent builds will not be executed if no trigger is set. There are 5 types of triggers

  • 触发远程构建 (例如,使用脚本):Requires remote script or command triggering, which is the same as manual execution, so it is generally not used
  • Build after other projects are built:Execute this build task after completing a certain build task. If the sequence in the pipeline is completed, the execution of this task will only be triggered when the previous step is completed. It is suitable for multiple related build tasks.
  • Build periodically:Trigger the build regularly, similar to the configuration of the crontab script, you can specify the build time, such as execution at 9 o'clock every day or 9 o'clock on Monday
  • GitHub hook trigger for GITScm polling:After submitting the code to GitHub, Jenkins will automatically build
  • Poll SCM:The upgraded version triggers the build periodically. The area with Build periodically is to check whether the source code is updated regularly. Only when the code is updated will it be triggered. Build periodically is only executed periodically, without judging whether to update the code.
  • 备注:Timed trigger construction is done through the configuration of the schedule, and the expression website is generated: http://www.bejson.com/othertools/cron/
    Insert picture description here
    7. Construction environment:
    generally do not check, just understand it
    Delete workspace before build startsat the beginning of the generation before cleaning up the workspace
    Use secret text(s) or file(s)using an encrypted text file or
    Abort the build if it's stuckif there is a problem, it suspended construction of
    Add timestamps to the Console Outputthe console output to increase the time stamp
    Inspect build log for published Gradle build scanschecking generates a log to view the published Gradle build scanning
    With Antwith Ant
    8, set the building:
    this is the core part of Jenkins, all The tasks are all completed through construction, and one or more tasks can be created according to the requirements, just click to add the construction step. Here only two kinds of built, namely Windows and Linux / OS system
    execute windows batch command
    This option is to execute the command line under the windows, similar to the input cmd in the computer end. You can specify to call Python and Java commands on the command line to execute test scripts.
    Insert picture description here
    ②This execute shell
    is a script command executed under Linux. It is suitable for Linux systems. After python or java is installed, you can directly run through commands.
    Insert picture description here
    Supplement:
    Several other build methods can also be passed The installation and configuration of environment variables, which are executed directly through the command line, are relatively simple and not as free as these two methods.
    The build itself is just a process. If you need multiple processes, you can add multiple builds, but there will be a sequence between the builds, and the previous build can be executed before the next one can be executed. For example, add build A to perform remote deployment update testing. Environment, and then add build B to execute automated test scripts. Take Windows as an example, useexecute windows batch command, The first build executes the python environment deployment script, the second build executes the Python automated test script
    Insert picture description here
    9. Post-build operations:
    If you need to perform some finishing work after executing the build, you can add post-build operations and introduce two common operations
    build other projects
    • This is one of the most commonly used functions, which is to perform another build task after completion. You only need to enter the existing project to run another build task after the completion of this build operation.
    • There are also 3 options that trigger the next build condition, which are:
      • Execute after successful build
      • The build is unstable and still executed
      • Even if the build fails, it still executes
        Insert picture description here

②For E-mail notification
sending mail function, you only need to enter the recipient's email address, because the email notification has been configured in the system settings before. You can also enter multiple recipients at the same time, passing the ;interval. Check Send email notifications for every unstable build, and then send emails to the designated recipient's mailbox every time the build fails, and attach a log of the build failure so that relevant personnel can understand the execution results and execution errors.
Insert picture description here

Three, test and use ideas

1. Execute after the code is updated
2. Execute the guarantee interface and verify the timing tasks regularly every day

Guess you like

Origin blog.csdn.net/qq_38123721/article/details/103866858