Method and device for remotely deploying product folders using recursive functions
The method of remotely deploying product folders through recursive functions solves the deployment failure problem caused by the lack of decompression commands on the deployment server, and achieves an efficient and successful deployment process.
Patent Information
- Application Number
- CN202210254867.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-15
- Publication Date
- 2025-02-18
- Estimated Expiration
- 2042-03-15
AI Technical Summary
The existing devops pipeline requires decompression operations when deploying folder-type products, but the deployment server may not have decompression commands available, resulting in the deployment failure.
The method of remotely deploying product folders using recursive functions is not required. Recursive functions are called to remotely create and deploy folders and their contents by taking the full name of the local product folder and the deployment directory of the remote deployment server as parameters of the recursive function.
Avoid deployment failures, improve deployment success rates, and simplify deployment processes, eliminating the complexity of compression operations.
Smart Images

Figure CN114741089B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of deploying artifact folders, and in particular to a method and device for remotely deploying artifact folders using a recursive function. Background Art
[0002] When deploying folder-type artifacts, the existing devops pipeline usually compresses the folder before deployment to generate a separate binary file. After uploading the binary file to the deployment server, it calls a remote command to decompress the binary file and then deletes the original binary file. However, when executing the decompression command on the deployment server, the deployment server may not have an available decompression command, which will cause the deployment of folder-type artifacts to fail and reduce deployment efficiency. Common compression formats include zip, rar, jar, 7z, cab, ace, gz, bz2, etc. Different compression formats require different decompression tools for decompression.
[0003] Therefore, it is necessary to provide a method to deploy artifact folders without the need for decompression operations. Summary of the invention
[0004] The purpose of the present application is to provide a method, device, electronic device and computer-readable storage medium for remotely deploying a product folder using a recursive function, which does not require a decompression operation and helps avoid deployment failures.
[0005] To achieve the above purpose, the present application provides a method for remotely deploying a product folder using a recursive function, comprising:
[0006] The full name of the local artifact folder is used as the initial first parameter of the recursive function, and the deployment directory of the remote deployment server is used as the initial second parameter of the recursive function, and the recursive function is called;
[0007] Get the name of the artifact folder from the initial first parameter;
[0008] The name of the artifact folder is concatenated to the end of the initial second parameter to form the full name of the deployment folder, and the deployment folder is remotely created on the remote deployment server using the full name;
[0009] Traverse the files and subfolders under the product folder. If a file exists, obtain the file name corresponding to the file and concatenate it to the full name of the deployment folder to form the file deployment full name, and transmit the file to the remote deployment server and become a file defined by the file deployment full name in the remote deployment server. If a subfolder exists, obtain the name of the subfolder and concatenate it to the initial first parameter as the new first parameter, use the full name of the deployment folder as the new second parameter, and call the recursive function.
[0010] Optionally, the method further includes: using a path separator as an identifier, and taking the content after the last path separator in the initial first parameter as the name of the product folder.
[0011] Optionally, the "transferring the file to the remote deployment server and becoming a file defined by the full name of the file deployment in the remote deployment server" is executed using an scp command.
[0012] Optionally, the method is a method for deploying a product folder in a devops pipeline.
[0013] To achieve the above purpose, the present application also provides a device for remotely deploying a product folder using a recursive function, comprising:
[0014] A calling module, used to take the full name of the local artifact folder as the initial first parameter of the recursive function, take the deployment directory of the remote deployment server as the initial second parameter of the recursive function, and call the recursive function;
[0015] An acquisition module, used for acquiring the name of the product folder from the initial first parameter;
[0016] A concatenation and creation module, used for concatenating the name of the product folder to the end of the initial second parameter to form the full name of the deployment folder, and remotely creating the deployment folder on the remote deployment server using the full name;
[0017] A traversal processing module is used to traverse the files and subfolders under the product folder. If a file exists, the file name corresponding to the file is obtained and concatenated to the end of the full name of the deployment folder to form a file deployment full name, and the file is transmitted to the remote deployment server and becomes a file defined by the file deployment full name in the remote deployment server. If a subfolder exists, the name of the subfolder is obtained and concatenated to the end of the initial first parameter as a new first parameter, and the full name of the deployment folder is used as a new second parameter to call the recursive function.
[0018] Optionally, the method further includes: using a path separator as an identifier, and taking the content after the last path separator in the initial first parameter as the name of the product folder.
[0019] Optionally, the "transferring the file to the remote deployment server and becoming a file defined by the full name of the file deployment in the remote deployment server" is executed using an scp command.
[0020] Optionally, the device is a device for deploying a product folder in a devops pipeline.
[0021] To achieve the above object, the present application also provides an electronic device, including:
[0022] processor;
[0023] a memory storing executable instructions of the processor;
[0024] The processor is configured to execute the method of remotely deploying a product folder using a recursive function as described above by executing the executable instructions.
[0025] To achieve the above objectives, the present application also provides a computer-readable storage medium on which a program is stored, and when the program is executed by a processor, the method of remotely deploying a product folder using a recursive function as described above is implemented.
[0026] The present application also provides a computer program product or a computer program, which includes a computer instruction stored in a computer-readable storage medium. A processor of an electronic device reads the computer instruction from the computer-readable storage medium, and the processor executes the computer instruction, so that the electronic device executes the method of remotely deploying a product folder using a recursive function as described above.
[0027] The present application uses the full name of the local product folder and the deployment directory of the remote deployment server as the first parameter and the second parameter of the recursive function, respectively, and thus calls the recursive function to perform the following operations: obtain the name of the product folder from the first parameter and splice it after the second parameter to form the full name of the deployment folder and remotely create a deployment folder based on the full name, then traverse the files and subfolders under the product folder, splice the file name of the existing file to the back of the deployment folder to form the full name of the file deployment and transmit the file as a file defined by the full name of the file deployment in the remote deployment server, splice the name of the existing subfolder after the first parameter as the new first parameter, and use the full name of the deployment folder as the new second parameter, and continue to call the recursive function to remotely deploy the subfolder. By analogy, as long as there are folders in the next level directory, continue to call the recursive function for processing until the deployment of the folders in the lowest level directory is completed. At this time, the remote deployment server successfully deploys a folder with the same directory structure as the local product folder under the deployment directory. The present application provides a new method for deploying folders, which does not require decompression operations, is conducive to avoiding deployment failures, and improves the success rate of deployment. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] Figure 1 It is a schematic diagram of the initial first parameter in the embodiment of the present application.
[0029] Figure 2 It is a schematic diagram of the initial second parameter in the embodiment of the present application.
[0030] Figure 3 It is a schematic diagram of obtaining the name of the product folder in an embodiment of the present application.
[0031] Figure 4 It is a schematic diagram of the full name of the deployment folder spliced together in an embodiment of the present application.
[0032] Figure 5 It is a schematic diagram of traversing files and subfolders in a product folder in an embodiment of the present application.
[0033] Figure 6 It is a schematic diagram of the full name of the file deployment spliced together in the embodiment of the present application.
[0034] Figure 7 It is a schematic diagram of the new first parameter in the embodiment of the present application.
[0035] Figure 8 It is a schematic diagram of the new second parameter in the embodiment of the present application.
[0036] Fig. 9 It is a schematic diagram of obtaining the name of a subfolder in an embodiment of the present application.
[0037] Fig.10 It is a schematic diagram of the full name of the deployment subfolder spliced together in the embodiment of the present application.
[0038] Fig.11 It is a schematic diagram of traversing files and grandchildren folders in a subfolder in an embodiment of the present application.
[0039] Fig.12 It is a schematic diagram of the full name of the sub-file deployment formed by splicing in an embodiment of the present application.
[0040] Fig.13 It is a schematic diagram of another first parameter in the embodiment of the present application.
[0041] Fig.14 It is a schematic diagram of another second parameter in the embodiment of the present application.
[0042] Fig.15 It is a flowchart of a method for remotely deploying a product folder using a recursive function according to an embodiment of the present application.
[0043] Fig.16 It is a schematic block diagram of an apparatus for remotely deploying a product folder using a recursive function according to an embodiment of the present application.
[0044] Fig.17 It is a schematic block diagram of an electronic device according to an embodiment of the present application. DETAILED DESCRIPTION
[0045] In order to explain the technical content, structural features, achieved objectives and effects of the present application in detail, the following is a detailed description in conjunction with the implementation methods and the accompanying drawings.
[0046] See also Figures 1 to 15 , the embodiment of the present application discloses a method for remotely deploying a product folder using a recursive function, comprising:
[0047] 101. The full name of the local product folder is used as the initial first parameter of the recursive function, and the deployment directory of the remote deployment server is used as the initial second parameter of the recursive function, and the recursive function is called.
[0048] In this application, "the full name of the artifact folder" refers to the path of the artifact folder plus the name of the artifact folder. For ease of understanding, please refer to Figure 1 , which gives an example of the full name of the artifact folder " / a / b / c", where "c" refers to the name of the artifact folder, " / a / b" can be regarded as the path of the artifact folder, and " / " refers to the path separator.
[0049] The "deployment directory of the remote deployment server" refers to the deployment path of a folder with the same directory structure as the artifact folder on the remote deployment server. For easier understanding, refer to Figure 2 , which gives an example of a deployment directory of a remote deployment server. In this example, the deployment directory or deployment path is: " / 1 / 2 / 3".
[0050] 102. Get the name of the artifact folder from the initial first parameter.
[0051] After calling the recursive function, you can use it to execute the deployment job. In order to create a folder with the same directory structure as the artifact folder on the remote deployment server, the recursive function will get the name of the artifact folder from the initial first parameter (the full name of the artifact folder). For easier understanding, please combine Figure 1 and Figure 3 ,in Figure 3 Shows from Figure 1 The name of the artifact folder "c" is obtained from the initial first parameter " / a / b / c".
[0052] Specifically, in order to facilitate obtaining the name of the product folder from the initial first parameter, the path separator is used as an identifier, and the content after the last path separator in the initial first parameter is taken as the name of the product folder.
[0053] Specifically, when obtaining the name of the artifact folder from the initial first parameter, the path separator that separates the name of the artifact folder from its path can also be obtained. Figure 3 In the example, " / c" is obtained.
[0054] 103. Concatenate the name of the artifact folder to the end of the initial second parameter to form the full name of the deployment folder, and use the full name to remotely create the deployment folder on the remote deployment server.
[0055] After getting the name of the artifact folder from the initial first parameter, the recursive function can concatenate the name of the artifact folder to the initial second parameter to form the full name of the deployment folder. After getting the full name of the deployment folder, the recursive function can use the full name to remotely create a deployment folder, that is, create a deployment folder with the full name.
[0056] In this application, "deployment folder" refers to the folder that needs to be deployed on the remote deployment server and corresponds to the local product folder. "Full name of deployment folder" is the path of deployment folder plus the name of deployment folder, where the path of deployment folder is the deployment directory of the remote deployment server mentioned above (the second initial parameter), and the name of deployment folder is the same as the name of product folder, so the full name of deployment folder can be obtained by concatenating the name of product folder after the second initial parameter.
[0057] For easier understanding, please combine Figure 2 , Figure 3 and Figure 4 In the specific example, the name of the artifact folder "c" is concatenated with the initial second parameter " / 1 / 2 / 3" to obtain the full name of the deployment folder " / 1 / 2 / 3 / c", and then a deployment folder with the full name " / 1 / 2 / 3 / c" can be created on the remote deployment server.
[0058] 104. Traverse the files and subfolders under the product folder. If a file exists, obtain the file name corresponding to the file and concatenate it to the full name of the deployment folder to form the file deployment full name, and transfer the file to the remote deployment server and become a file defined by the file deployment full name in the remote deployment server. If a subfolder exists, obtain the name of the subfolder and concatenate it to the initial first parameter as the new first parameter, use the full name of the deployment folder as the new second parameter, and call the recursive function.
[0059] After completing the creation of the deployment folder, the recursive function can perform the traversal of the product folder. For existing files, the file name and the full name of the deployment folder are concatenated to form the file deployment full name. Then, based on the file deployment full name, the file can be transferred to the deployment folder of the remote deployment server to become a file defined by the file deployment full name. For existing subfolders, the name of the subfolder is concatenated after the initial first parameter as the new first parameter, and the full name of the deployment folder is used as the new second parameter. Then, the recursive function can be called again to perform remote deployment on the subfolder.
[0060] For easier understanding, please combine Figures 5 to 14In this example, all files and subfolders under the artifact folder with the full name " / a / b / c" are traversed. For any existing file, the file name "test.txt" corresponding to the file is taken and concatenated to the full name of the deployment folder " / 1 / 2 / 3 / c" to form the file deployment full name " / 1 / 2 / 3 / ctest.txt". Then, based on the file deployment full name " / 1 / 2 / 3 / c test.txt", the file "test.txt" is uploaded to the deployment folder with the full name " / 1 / 2 / 3 / c".
[0061] For any existing subfolder, the name of the subfolder "d" is concatenated after the initial first parameter " / a / b / c" as the new first parameter " / a / b / c / d", and the full name of the deployment folder " / 1 / 2 / 3 / c" is used as the new second parameter. Then the recursive function can be called again based on the new first parameter " / a / b / c / d" and the new second parameter " / 1 / 2 / 3 / c". The recursive function can perform remote deployment for the subfolder, that is, perform the same operation as remote deployment for the artifact folder:
[0062] Please combine the specific Figures 5 to 14 First, get the name "d" of the subfolder from the new first parameter " / a / b / c / d". Then, concatenate the name "d" of the subfolder to the new second parameter " / 1 / 2 / 3 / c" to get the full name " / 1 / 2 / 3 / c / d" of the deployment subfolder, and create a deployment subfolder with the full name " / 1 / 2 / 3 / c / d" on the remote deployment server. Then, traverse the files and grandchild folders under the subfolder. If a file exists, get the file name "test2.txt" corresponding to the file and concatenate it to the full name " / 1 / 2 / 3 / c / d" of the deployment subfolder to form the full name of the sub-file deployment " / 1 / 2 / 3 / c / d test2.txt", and transmit the file test2.txt to the remote deployment server and become the full name of the sub-file deployment " / 1 / 2 / 3 / c / d" in the remote deployment server. test2.txt" is defined. If a grandchild folder exists, the name of the grandchild folder "e" is obtained and concatenated after the first parameter " / a / b / c / d" as the first parameter " / a / b / c / d / e", and the full name of the deployed subfolder / 1 / 2 / 3 / c / d is used as the second parameter. The recursive function continues to be called, and so on, until the folder under the lowest level directory is deployed on the remote deployment server. At this point, a folder with the same directory structure as the local product folder is successfully deployed on the remote deployment server (folders and files at all levels are deployed).
[0063] Specifically, "transferring the file to the remote deployment server and making it a file defined by the full name of the file deployment in the remote deployment server" is executed by using the scp command.
[0064] Specifically, the method for remotely deploying a product folder using a recursive function in the present application is a method for deploying a product folder in a devops pipeline. The local product folder is a local folder after the devops pipeline is successfully built.
[0065] The present application uses the full name of the local product folder and the deployment directory of the remote deployment server as the first parameter and the second parameter of the recursive function, respectively, and thus calls the recursive function to perform the following operations: obtain the name of the product folder from the first parameter and splice it after the second parameter to form the full name of the deployment folder and remotely create a deployment folder based on the full name, then traverse the files and subfolders under the product folder, splice the file name of the existing file to the back of the deployment folder to form the full name of the file deployment and transmit the file as a file defined by the full name of the file deployment in the remote deployment server, splice the name of the existing subfolder after the first parameter as the new first parameter, and use the full name of the deployment folder as the new second parameter, and continue to call the recursive function to remotely deploy the subfolder. By analogy, as long as there are folders in the next level directory, continue to call the recursive function for processing until the deployment of the folders in the lowest level directory is completed. At this time, the remote deployment server successfully deploys a folder with the same directory structure as the local product folder under the deployment directory. The present application provides a new method for deploying folders, which does not require decompression operations, is conducive to avoiding deployment failures, and improves the success rate of deployment.
[0066] Please combine Figures 1 to 16 , the embodiment of the present application discloses a device for remotely deploying a product folder using a recursive function, comprising:
[0067] 201. A calling module, used to use the full name of the local artifact folder as the initial first parameter of the recursive function, and the deployment directory of the remote deployment server as the initial second parameter of the recursive function, to call the recursive function;
[0068] 202. An acquisition module, used to obtain the name of the product folder from the initial first parameter;
[0069] 203. A concatenation and creation module, used to concatenate the name of the product folder to the end of the initial second parameter to form the full name of the deployment folder, and remotely create the deployment folder on the remote deployment server using the full name;
[0070] 204. A traversal processing module is used to traverse the files and subfolders under the product folder. If a file exists, the file name corresponding to the file is obtained and concatenated to the full name of the deployment folder to form the file deployment full name, and the file is transmitted to the remote deployment server and becomes a file defined by the file deployment full name in the remote deployment server. If a subfolder exists, the name of the subfolder is obtained and concatenated to the initial first parameter as a new first parameter, and the full name of the deployment folder is used as the new second parameter to call a recursive function.
[0071] The present application uses the full name of the local product folder and the deployment directory of the remote deployment server as the first parameter and the second parameter of the recursive function, respectively, and thus calls the recursive function to perform the following operations: obtain the name of the product folder from the first parameter and splice it after the second parameter to form the full name of the deployment folder and remotely create a deployment folder based on the full name, then traverse the files and subfolders under the product folder, splice the file name of the existing file to the back of the deployment folder to form the full name of the file deployment and transmit the file as a file defined by the full name of the file deployment in the remote deployment server, splice the name of the existing subfolder after the first parameter as the new first parameter, and use the full name of the deployment folder as the new second parameter, and continue to call the recursive function to remotely deploy the subfolder. By analogy, as long as there are folders in the next level directory, continue to call the recursive function for processing until the deployment of the folders in the lowest level directory is completed. At this time, the remote deployment server successfully deploys a folder with the same directory structure as the local product folder under the deployment directory. The present application provides a new method for deploying folders, which does not require decompression operations, is conducive to avoiding deployment failures, and improves the success rate of deployment.
[0072] For a detailed description of the device for remotely deploying a product folder using a recursive function, please refer to the description of the method for remotely deploying a product folder using a recursive function mentioned above, which will not be repeated here.
[0073] Please combine Fig.17 , the embodiment of the present application further discloses an electronic device, which includes:
[0074] Processor 31;
[0075] A memory 30 storing executable instructions of a processor 31;
[0076] The processor 31 is configured to execute the above-mentioned method of remotely deploying a product folder using a recursive function by executing executable instructions.
[0077] The present application also provides a computer-readable storage medium on which a program is stored. When the program is executed by a processor, the above-mentioned method of remotely deploying a product folder using a recursive function is implemented.
[0078] The embodiment of the present application also discloses a computer program product or a computer program, which includes a computer instruction stored in a computer-readable storage medium. A processor of an electronic device reads the computer instruction from the computer-readable storage medium, and the processor executes the computer instruction, so that the electronic device executes the above-mentioned method of remotely deploying a product folder using a recursive function.
[0079] It should be understood that in the embodiments of the present application, the processor referred to may be a central processing unit (CPU), and the processor may also be other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.
[0080] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by hardware related to computer program instructions, and the program can be stored in a computer-readable storage medium, which, when executed, can include the processes of the above-mentioned embodiments of the methods. The storage medium can be a disk, an optical disk, a read-only memory (ROM) or a random access memory (RAM), etc.
[0081] The above disclosure is only a preferred example of the present application and cannot be used to limit the scope of rights of the present application. Therefore, equivalent changes made according to the claims of the present application are all within the scope covered by the present application.
Claims
1. A method for remotely deploying a product folder using a recursive function, characterized in that: include: The full name of the local artifact folder is used as the initial first parameter of the recursive function, and the deployment directory of the remote deployment server is used as the initial second parameter of the recursive function, and the recursive function is called; Get the name of the artifact folder from the initial first parameter; The name of the artifact folder is concatenated to the end of the initial second parameter to form the full name of the deployment folder, and the deployment folder is remotely created on the remote deployment server using the full name; Traverse the files and subfolders under the product folder, if there is a file, obtain the file name corresponding to the file and concatenate it to the full name of the deployment folder to form the file deployment full name, and transmit the file to the remote deployment server and become a file defined by the file deployment full name in the remote deployment server, if there is a subfolder, obtain the name of the subfolder and concatenate it to the initial first parameter as a new first parameter, use the full name of the deployment folder as a new second parameter, and call the recursive function; The file is transmitted to the remote deployment server and becomes a file defined by the full name of the file deployment in the remote deployment server and is executed by the scp command; The method is a method for deploying a product folder in a devops pipeline.
2. The method for remotely deploying a product folder using a recursive function as claimed in claim 1, characterized in that: Also includes: The path separator is used as an identifier, and the content after the last path separator in the initial first parameter is taken as the name of the product folder.
3. A device for remotely deploying a product folder using a recursive function, characterized in that: include: A calling module, used to take the full name of the local artifact folder as the initial first parameter of the recursive function, take the deployment directory of the remote deployment server as the initial second parameter of the recursive function, and call the recursive function; An acquisition module, used for acquiring the name of the product folder from the initial first parameter; A concatenation and creation module, used for concatenating the name of the product folder to the end of the initial second parameter to form the full name of the deployment folder, and remotely creating the deployment folder on the remote deployment server using the full name; A traversal processing module, used to traverse the files and subfolders under the product folder, if a file exists, obtain the file name corresponding to the file and concatenate it to the end of the full name of the deployment folder to form a file deployment full name, and transmit the file to the remote deployment server and become a file defined by the file deployment full name in the remote deployment server, if a subfolder exists, obtain the name of the subfolder and concatenate it to the end of the initial first parameter as a new first parameter, use the full name of the deployment folder as a new second parameter, and call the recursive function; The file is transmitted to the remote deployment server and becomes a file defined by the full name of the file deployment in the remote deployment server and is executed by the scp command; The device is a device for deploying artifact folders in the devops pipeline.
4. The device for remotely deploying a product folder using a recursive function as claimed in claim 3, characterized in that: Also includes: The path separator is used as an identifier, and the content after the last path separator in the initial first parameter is taken as the name of the product folder.
5. An electronic device, characterized in that: include: processor; a memory storing executable instructions of the processor; The processor is configured to execute the method of remotely deploying a product folder using a recursive function as described in claim 1 or 2 by executing the executable instructions.
6. A computer-readable storage medium having a program stored thereon, characterized in that: When the program is executed by a processor, the method for remotely deploying a product folder using a recursive function as described in claim 1 or 2 is implemented.
Citation Information
Patent Citations
Electronic file uploading method and system
CN113286001A