Jenkins compilation task creation method and device
By automatically detecting changes in external attributes of the code warehouse and updating the source code management configuration information, the problem of Jenkins compilation task creation relying on human maintenance is solved, and the timeliness and accuracy of compilation tasks is achieved, improving efficiency and reducing costs.
Patent Information
- Application Number
- CN202111176505.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-10-09
- Publication Date
- 2025-04-22
- Estimated Expiration
- 2041-10-09
AI Technical Summary
In the prior art, the creation of Jenkins compilation tasks is solely maintained by human resources. The compilation is relatively passive and untimely, resulting in low efficiency and untimely.
By determining whether the external properties of the code repository have changed, the source code management configuration information is automatically updated, thereby creating a compilation task that can obtain the correct version of the project code in a timely manner.
It realizes automatic updates of Jenkins compilation tasks, ensuring that the compilation tasks can obtain the correct version of the project code in a timely manner, improves compilation efficiency, and reduces labor costs and error rates.
Smart Images

Figure CN113986237B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of software development, and in particular to a method, device, electronic device, and storage medium for creating a Jenkins compilation task. Background Art
[0002] In the current daily work of the IT industry, software compilation and deployment are important parts of software development, and they often take a lot of time to process. Jenkins is an open source continuous integration (CI) tool that provides a user-friendly interface. It is mainly used to continuously and automatically build / test software projects and monitor the operation of external tasks. However, the creation of Jenkins compilation tasks currently relies solely on manual maintenance, and compilation is relatively passive and untimely. It is often necessary to locate and update the problem only when it occurs, which consumes a lot of manpower. Summary of the invention
[0003] The technical problem to be solved by the present invention is to overcome the defects in the prior art that the creation of Jenkins compilation tasks relies solely on manual maintenance, and the compilation is relatively passive and untimely, and to provide a method, device, electronic device, and storage medium for creating a Jenkins compilation task.
[0004] The present invention solves the above technical problems through the following technical solutions:
[0005] In a first aspect, a method for creating a Jenkins compilation task is provided, which is applied to an electronic device, wherein a plurality of code repositories are deployed on the electronic device, the code repositories are used to store project codes, and each code repositories is configured with an external attribute for describing a repository address of the code repositories; the creation method comprises:
[0006] Determine whether the external properties of each code repository have changed;
[0007] In the case where it is determined that the external attribute of at least one code repository has changed, determining that the structure of the project code has changed;
[0008] The source code management configuration information is updated according to the external attribute, and the updated source code management configuration information is used to create a compilation task, wherein the source code management configuration information records a warehouse address.
[0009] Optionally, it also includes:
[0010] Get the external properties of each code repository;
[0011] Establishing a mapping relationship between components included in the code address of the project code and external attributes of each code repository, wherein the code address changes according to changes in the external attributes;
[0012] When it is identified that the code address has changed, it is determined that the external attribute of the at least one code repository has changed.
[0013] Optionally, get the external properties of each repository, including:
[0014] Execute the script to recursively traverse each code repository and obtain the external properties of each code repository.
[0015] Optionally, determine whether the external properties of each code repository have changed, including:
[0016] Regularly determine whether the external attributes of each code repository have changed;
[0017] Alternatively, determine whether the external attributes of each code repository have changed according to a preset period.
[0018] Optionally, it also includes:
[0019] In response to a change request for an external attribute, the external attribute is changed according to the change request.
[0020] In a second aspect, a Jenkins compilation task creation device is provided, which is applied to an electronic device, wherein a plurality of code repositories are deployed on the electronic device, wherein the code repositories are used to store project codes, and each code repositories is configured with an external attribute for describing a repository address of the code repositories; the creation device comprises:
[0021] The first determination module is used to determine whether the external attributes of each code repository have changed;
[0022] A second determining module is used to determine that the structure of the project code has changed when it is determined that the external attribute of at least one code repository has changed;
[0023] An update module is used to update source code management configuration information according to the external attribute, and the updated source code management configuration information is used to create a compilation task, and the source code management configuration information records a warehouse address.
[0024] Optionally, it also includes:
[0025] The acquisition module is used to obtain the external attributes of each code repository;
[0026] An establishment module is used to establish a mapping relationship between components included in the code address of the project code and external attributes of each code repository, wherein the code address changes according to changes in the external attributes;
[0027] The first determining module is configured to determine that an external attribute of the at least one code repository has changed when a change in the code address is identified.
[0028] Optionally, the acquisition module is specifically used for:
[0029] Execute the script to recursively traverse each code repository and obtain the external properties of each code repository.
[0030] Optionally, the first determining module is specifically configured to:
[0031] Regularly determine whether the external attributes of each code repository have changed;
[0032] Alternatively, determine whether the external attributes of each code repository have changed according to a preset period.
[0033] Optionally, it also includes:
[0034] The modification module is used to respond to a modification request of an external attribute and modify the external attribute according to the modification request.
[0035] In a third aspect, an electronic device is provided, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the method for creating a Jenkins compilation task described in any one of the above items when executing the computer program.
[0036] In a fourth aspect, a computer-readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the method for creating a Jenkins compilation task described in any one of the above items is implemented.
[0037] The positive and progressive effect of the present invention is that in the embodiment of the present invention, when it is determined that the external attributes of the code repository have changed, the source code management configuration information is automatically updated, so that the compilation task created based on the updated source code management configuration information can obtain the correct version of the project code and compile it effectively and timely. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] Figure 1 A flowchart of a method for creating a Jenkins compilation task provided by an exemplary embodiment of the present invention;
[0039] Figure 2 A flowchart of a method for determining whether external properties of a code repository have changed during the creation of a Jenkins compilation task provided by an exemplary embodiment of the present invention;
[0040] Figure 3 A module schematic diagram of a Jenkins compilation task creation device provided by an exemplary embodiment of the present invention;
[0041] Figure 4The present invention is a schematic structural diagram of an electronic device according to an exemplary embodiment of the present invention. DETAILED DESCRIPTION
[0042] The present invention is further described below by way of examples, but the present invention is not limited to the scope of the examples.
[0043] For a large project with multiple code repositories, it is necessary to establish a Jenkins compilation task to continuously verify the work results of the development engineers at the beginning of the project code development phase. The creation and update of Jenkins compilation tasks are very tricky, and often involve as many configuration items as the number of code repositories, and these configuration items will change frequently over time. For example, for project A, its code is stored in multiple code repositories. In order to achieve compilation, the project manager PM (or developer) must configure the warehouse address of each code repository to correctly obtain the downloaded code. The multi-repository configuration requires the local address of each sub-repository relative to the parent repository, plus the external link address of the sub-repository. Manual configuration is very cumbersome. When compiling project A based on the Jenkins system, all the code of project A can be obtained and compiled based on the code address. Assume that project A just started using the V1 version of module a. After a period of development evolution, the project manager PM of project A decided to use the V2 version of module a. Currently, the Jenkins system cannot automatically detect the above changes, and cannot automatically update the repository address. The project code obtained based on the original repository address is incorrect, and the compilation is invalid or incorrect, unless the project manager PM manually updates the repository address. For large projects with multiple code repositories, manually updating the code address is prone to errors, inefficient, and untimely.
[0044] Based on the above problems, an embodiment of the present invention provides a method for creating a Jenkins compilation task.
[0045] Figure 1 A flowchart of a method for creating a Jenkins compilation task is provided as an exemplary embodiment of the present invention. The creation method is applied to an electronic device, which may be, for example, a server, which may be a physical server including an independent host, or a virtual server hosted by a host cluster. Multiple code repositories are created on the electronic device, and the code repositories are used to store project codes, and each code repositories is configured with external properties.
[0046] See also Figure 1 , the creation method includes the following steps:
[0047] Step 101: Determine whether the external attributes of each code repository have changed.
[0048] The external attribute is used to describe the repository address, which includes a local address (also called an internal path) and / or an external link address (URL). The external link address of a code repository represents the address of other code repositories that have a dependency relationship with the code repository. The repository address can be represented by, but is not limited to, the domain name and port number of the server where the code repository is deployed.
[0049] In one embodiment, it is determined at regular intervals whether the external attributes of each code repository have changed. The time point for determining whether the external attributes of each code repository have changed can be set according to actual needs; it can also be determined based on historical experience. For example, if developers generally complete the update of project code (such as updating the version) around 8:00 on Friday, it is set to determine whether the external attributes of each code repository have changed at 8:00 on Friday. Determining the timing of whether the external attributes have changed based on historical experience can reduce the number of times the external attributes have been determined to have changed, thereby reducing the amount of calculation.
[0050] In one embodiment, it is determined whether the external attributes of each code repository have changed according to a preset period. The preset period can be set according to actual conditions. It can be understood that the smaller the preset period is set, the more frequent the number of times the external attributes are determined to have changed, the more timely the changes in the external attributes can be discovered, and the source code management configuration information can be updated in a timely manner. This allows the compilation task created based on the updated source code management configuration information to obtain the correct project code for effective compilation, avoiding the acquisition of other versions of the project code.
[0051] Step 102: When it is determined that the external attribute of at least one code repository has changed, it is determined that the structure of the project code has changed.
[0052] If the external attributes of all code repositories have not changed, it is determined that the topological structure of the code repositories has not changed, that is, the structure of the project code has not changed, and step 103 does not need to be performed.
[0053] If the external attributes of at least one code repository have not changed, it is determined that the topological structure of the code repository has changed, that is, the structure of the project code has changed, and step 103 needs to be executed.
[0054] Step 103: Update source code management configuration information according to the external attribute. The updated source code management configuration information is used to create a compilation task. The source code management configuration information records the warehouse address.
[0055] In the embodiment of the present invention, when it is determined that the external attributes of the code repository have changed, the source code management configuration information is automatically updated, so that the compilation task created based on the updated source code management configuration information can obtain the correct version of the project code and compile it effectively and timely; thereby effectively reducing the situation where the code assembled according to the old source code management configuration information cannot be used due to the failure to notify synchronization in time when the modules of the project are changed. And there is no need to manually update the source code management configuration information, which can save labor costs and reduce the error rate of manually updating the source code management configuration information.
[0056] The compilation task may be created after the source code management configuration information is updated, and the compilation task is executed to obtain the project code corresponding to the warehouse address recorded in the source code management configuration information and compile it.
[0057] The compilation task can be created when a compilation request is received, that is, when the developer has a compilation requirement, the compilation task is created according to the updated source code management configuration information, instead of creating the compilation task immediately after the source code management configuration information is updated.
[0058] In one embodiment, whether the external attribute of the code repository has changed is determined by identifying whether the code address of the pre-established project code has changed. Figure 2 , including the following steps:
[0059] Step 201: Obtain external attributes of each code repository.
[0060] In one embodiment, each code repository is traversed by executing a script to automatically obtain the external attributes of each code repository. The external attributes include the local address and
[0061] Step 202: Establish a mapping relationship between the components contained in the code address of the project code and the external attributes of each code repository.
[0062] The code address changes according to the changes of external attributes. The code address includes the repository addresses of all code repositories included in the project.
[0063] For example, suppose the project code has three code repositories, and the external attributes of the three code repositories are attribute a, attribute b, and attribute c. Correspondingly, the code address contains three components, namely component A, component B, and component C. The code address is expressed as: component A / component B / component C. A mapping relationship is established between component A and attribute a, and when attribute a changes, the corresponding component A will also change; a mapping relationship is established between component B and attribute b, and when attribute b changes, the corresponding component B will also change; a mapping relationship is established between component C and attribute c, and when attribute c changes, the corresponding component C will also change.
[0064] Therefore, by establishing a mapping relationship between the code address of the project code and the external attributes, the code address is no longer a fixed address, but a relative address, and the code address will change according to the changes of the external attributes.
[0065] Step 203: When a change in the code address is identified, determine that an external attribute of at least one code repository has changed.
[0066] Since a mapping relationship is established between code addresses and external attributes, a change in code address indicates a change in external attributes. Therefore, by identifying whether the code address has changed, it is possible to determine whether the external attributes of each code repository have changed. In this way, it is possible to determine whether the external attributes of each code repository have changed without polling or traversing each code repository. This is simple to implement and requires less computation.
[0067] In one embodiment, after completing the version change of the code repository, the developer requests to change the external attribute, and the electronic device responds to the change request of the external attribute and changes the external attribute according to the change request. Based on the change of the external attribute by the developer, the electronic device will correspondingly update the warehouse address recorded in the source code management configuration information.
[0068] In one embodiment, if a project includes N code repositories, a script is executed regularly to implement the following steps: obtaining the external link address (URL) and local address (path) mapping of the entry code repository (1 code repository among the N code repositories), recursively traversing the external properties of the N code repositories to obtain the external link address (URL) and local address (path) mapping of the N code repositories, automatically constructing Jenkins source code management configuration information, and the constructed Jenkins source code management configuration is used to create a compilation task. By regularly obtaining the external link address (URL) and local address (path) mapping of the N code repositories, comparing the Jenkins source code management configuration information, the code repository that needs to be adjusted is found and the Jenkins source code management configuration information of the corresponding code repository is updated, and the updated Jenkins source code management configuration information is used to create a compilation task. Thus, when the external property configuration of the code repository changes, the Jenkins source code management configuration information is automatically updated, so that the compilation task created based on the updated Jenkins source code management configuration information can obtain the correct version of the project code and compile it effectively and timely.
[0069] In an embodiment of the present invention, when configuring a Jenkins task for the first time, for multi-warehouse source code management, only a configuration file needs to be created. The configuration file only needs to contain one pair of external link address (URL) and local address (path) mapping of the entry code library. The external link address (URL) and local address (path) mapping of the remaining N-1 pairs of sub-code repositories at each level are obtained through automatic traversal and generate a Jenkins configuration file. The system automatically creates a Jenkins task through the configuration file, without the need to manually configure source code management for N code repositories (each code library needs to be configured with a pair of external link address (URL) and local address (path) mapping), and the entire automated compilation task creation becomes extremely easy.
[0070] Compared with the related art, all code libraries need to be manually configured when creating a new compilation task. In the embodiment of the present invention, by executing a script (including the external link address and local address mapping of the entry code library) instead of manually configuring all information directly on Jerkins, the convenience is greatly improved, thereby realizing automatic configuration of Jenkins.
[0071] Corresponding to the aforementioned embodiment of the method for creating a Jenkins compilation task, the present invention also provides an embodiment of an apparatus for creating a Jenkins compilation task.
[0072] Figure 3A schematic diagram of a module of a device for creating a Jenkins compilation task provided by an exemplary embodiment of the present invention, wherein the device is applied to a server, wherein multiple code repositories are deployed on the server, wherein the code repositories are used to store project codes, and each code repositories is configured with an external attribute for describing the repository address of the code repositories; the device comprises:
[0073] A first determination module 31 is used to determine whether the external attributes of each code repository have changed;
[0074] A second determining module 32 is used to determine that the structure of the project code has changed when it is determined that the external attribute of at least one code repository has changed;
[0075] The updating module 33 is used to update the source code management configuration information according to the external attribute, and the updated source code management configuration information is used to create a compilation task, and the source code management configuration information records the warehouse address.
[0076] Optionally, it also includes:
[0077] The acquisition module is used to obtain the external attributes of each code repository;
[0078] An establishment module is used to establish a mapping relationship between components included in the code address of the project code and external attributes of each code repository, wherein the code address changes according to changes in the external attributes;
[0079] The first determining module is configured to determine that an external attribute of the at least one code repository has changed when a change in the code address is identified.
[0080] Optionally, the acquisition module is specifically used for:
[0081] Execute the script to traverse each code repository and obtain the external properties of each code repository.
[0082] Optionally, the first determining module is specifically configured to:
[0083] Regularly determine whether the external attributes of each code repository have changed;
[0084] Alternatively, determine whether the external attributes of each code repository have changed according to a preset period.
[0085] Optionally, it also includes:
[0086] The modification module is used to respond to a modification request of an external attribute and modify the external attribute according to the modification request.
[0087] For the device embodiment, since it basically corresponds to the method embodiment, the relevant parts can refer to the partial description of the method embodiment. The device embodiment described above is only schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of the present invention. Ordinary technicians in this field can understand and implement it without paying creative work.
[0088] Figure 4 The schematic diagram of the structure of an electronic device according to an exemplary embodiment of the present invention shows a block diagram of an exemplary electronic device 40 suitable for implementing the embodiment of the present invention. Figure 4 The electronic device 40 shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.
[0089] like Figure 4 As shown, the electronic device 40 may be in the form of a general-purpose computing device, for example, it may be a server device. The components of the electronic device 40 may include, but are not limited to: at least one processor 41, at least one memory 42, and a bus 43 connecting different system components (including the memory 42 and the processor 41).
[0090] The bus 43 includes a data bus, an address bus, and a control bus.
[0091] The memory 42 may include a volatile memory, such as a random access memory (RAM) 421 and / or a cache memory 422 , and may further include a read-only memory (ROM) 423 .
[0092] The memory 42 may also include a program tool 425 (or utility) having a set (at least one) of program modules 424, such program modules 424 including but not limited to: an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment.
[0093] The processor 41 executes various functional applications and data processing by running the computer program stored in the memory 42, such as the method provided in any of the above embodiments.
[0094] The electronic device 40 may also communicate with one or more external devices 44 (e.g., keyboards, pointing devices, etc.). Such communication may be performed via an input / output (I / O) interface 45. Furthermore, the model-generated electronic device 40 may also communicate with one or more networks (e.g., a local area network (LAN), a wide area network (WAN), and / or a public network, such as the Internet) via a network adapter 46. As shown, the network adapter 46 communicates with other modules of the model-generated electronic device 40 via a bus 43. It should be understood that, although not shown in the figure, other hardware and / or software modules may be used in conjunction with the model-generated electronic device 40, including but not limited to: microcode, device drivers, redundant processors, external disk drive arrays, RAID (disk array) systems, tape drives, and data backup storage systems, etc.
[0095] It should be noted that although several units / modules or sub-units / modules of the electronic device are mentioned in the above detailed description, this division is merely exemplary and not mandatory. In fact, according to an embodiment of the present invention, the features and functions of two or more units / modules described above can be embodied in one unit / module. Conversely, the features and functions of one unit / module described above can be further divided into multiple units / modules to be embodied.
[0096] An embodiment of the present invention further provides a computer-readable storage medium having a computer program stored thereon, and when the program is executed by a processor, the method provided by any of the above embodiments is implemented.
[0097] The readable storage medium may include but is not limited to: a portable disk, a hard disk, a random access memory, a read-only memory, an erasable programmable read-only memory, an optical storage device, a magnetic storage device or any suitable combination of the above.
[0098] In a possible implementation manner, the embodiment of the present invention may also be implemented in the form of a program product, which includes a program code. When the program product is run on a terminal device, the program code is used to enable the terminal device to execute a method for implementing any of the above embodiments.
[0099] The program code for executing the present invention may be written in any combination of one or more programming languages, and may be executed entirely on a user device, partially on a user device, as an independent software package, partially on a user device and partially on a remote device, or entirely on a remote device.
[0100] Although the specific embodiments of the present invention are described above, it should be understood by those skilled in the art that this is only for illustration and the protection scope of the present invention is defined by the appended claims. Those skilled in the art may make various changes or modifications to these embodiments without departing from the principles and essence of the present invention, but these changes and modifications all fall within the protection scope of the present invention.
Claims
1. A method for creating a Jenkins compilation task, characterized in that: Applied to an electronic device, wherein a plurality of code repositories are deployed on the electronic device, wherein the code repositories are used to store project codes, and each code repositories is configured with an external attribute for describing a repository address of the code repositories; the creation method comprises: Get the external properties of each code repository; Establishing a mapping relationship between components included in the code address of the project code and external attributes of each code repository, wherein the code address changes according to changes in the external attributes; In the case of identifying that the code address has changed, determining whether an external attribute of at least one code repository has changed; In the case where it is determined that the external attribute of at least one code repository has changed, determining that the structure of the project code has changed; The source code management configuration information is updated according to the external attribute, and the updated source code management configuration information is used to create a compilation task, wherein the source code management configuration information records a warehouse address.
2. The method for creating a Jenkins compilation task according to claim 1, characterized in that: Get the external properties of each code repository, including: Execute the script to recursively traverse each code repository and obtain the external properties of each code repository.
3. The method for creating a Jenkins compilation task according to claim 1, characterized in that: Determine whether the external properties of each code repository have changed, including: Regularly determine whether the external attributes of each code repository have changed; Alternatively, determine whether the external attributes of each code repository have changed according to a preset period.
4. The method for creating a Jenkins compilation task according to claim 1, characterized in that: Also includes: In response to a change request for an external attribute, the external attribute is changed according to the change request.
5. A device for creating a Jenkins compilation task, characterized in that: Applied to an electronic device, where a plurality of code repositories are deployed on the electronic device, the code repositories are used to store project codes, and each code repositories is configured with an external attribute for describing a repository address of the code repositories; The creation device comprises: The acquisition module is used to obtain the external attributes of each code repository; An establishment module is used to establish a mapping relationship between components included in the code address of the project code and external attributes of each code repository, wherein the code address changes according to changes in the external attributes; A first determination module is used to determine whether the external attribute of at least one code repository has changed when it is identified that the code address has changed; A second determining module is used to determine that the structure of the project code has changed when it is determined that the external attribute of at least one code repository has changed; An update module is used to update source code management configuration information according to the external attribute, and the updated source code management configuration information is used to create a compilation task, and the source code management configuration information records a warehouse address.
6. The device for creating a Jenkins compilation task according to claim 5, characterized in that: The acquisition module is specifically used for: Execute the script to recursively traverse each code repository and obtain the external properties of each code repository.
7. The device for creating a Jenkins compilation task according to claim 5, characterized in that: The first determining module is specifically used for: Regularly determine whether the external attributes of each code repository have changed; Alternatively, determine whether the external attributes of each code repository have changed according to a preset period.
8. The device for creating a Jenkins compilation task according to claim 5, characterized in that: Also includes: The modification module is used to respond to a modification request of an external attribute and modify the external attribute according to the modification request.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the method for creating a Jenkins compilation task according to any one of claims 1 to 4 is implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method for creating a Jenkins compilation task according to any one of claims 1 to 4 is implemented.
Citation Information
Patent Citations
Automatic program version issuing method and device
CN105653287A
Data table determination method and device based on change codes
CN110659293A