Disclosure of Invention
The application aims to provide a method, a device, electronic equipment and a computer readable storage medium for remotely deploying a product folder by using a recursive function, which do not need decompression operation and are beneficial to avoiding deployment failure.
To achieve the above object, the present application provides a method for remotely deploying an artifact folder using a recursive function, comprising:
the method comprises the steps of taking the full name of a local product folder as an initial first parameter of a recursive function, taking a deployment catalog of a remote deployment server as an initial second parameter of the recursive function, and calling the recursive function;
acquiring the names of the product folders from the initial first parameter;
Splicing names of the artifact folders behind the initial second parameter to form a full name of a deployment folder, and remotely creating the deployment folder on the remote deployment server by using the full name;
traversing the files and subfolders under the product folder, if the files exist, acquiring the file names corresponding to the files and splicing the file names to the back of the full names of the deployment folders to form file deployment full names, transmitting the files to the remote deployment server and becoming files defined by the file deployment full names in the remote deployment server, if the subfolders exist, acquiring the names of the subfolders and splicing the subfolders behind the initial first parameters to serve as new first parameters, and calling the full names of the deployment folders to serve as new second parameters.
Optionally, the method further comprises taking a path separator as an identifier, and taking the content behind the last path separator in the initial first parameter as the name of the product folder.
Optionally, the "transfer the file to the remote deployment server and become a file defined in the remote deployment server under the full name of the file deployment" is performed in a scp command.
Optionally, the method is a devops pipeline method of deploying the artifact folder.
To achieve the above object, the present application further provides an apparatus for remotely deploying an artifact folder using a recursive function, comprising:
the system comprises a calling module, a remote deployment server and a storage module, wherein the calling module is used for calling a local product folder with the full name of the initial first parameter of a recursive function and a deployment catalog of the remote deployment server as the initial second parameter of the recursive function;
the acquisition module is used for acquiring the names of the product folders from the initial first parameter;
the splicing and creating module is used for splicing the names of the product folders behind the initial second parameters to form the full names of the deployment folders, and remotely creating the deployment folders on the remote deployment server by utilizing the full names;
The traversing processing module is used for traversing the files and subfolders under the product folder, acquiring the file names corresponding to the files and splicing the file names to the back of the full names of the deployment folders to form file deployment full names, transmitting the files to the remote deployment server and becoming files defined by the file deployment full names in the remote deployment server, acquiring the names of the subfolders and splicing the names of the subfolders to serve as new first parameters after the initial first parameters if the subfolders exist, and calling the full names of the deployment folders to serve as new second parameters.
Optionally, the method further comprises taking a path separator as an identifier, and taking the content behind the last path separator in the initial first parameter as the name of the product folder.
Optionally, the "transfer the file to the remote deployment server and become a file defined in the remote deployment server under the full name of the file deployment" is performed in a scp command.
Optionally, the device is a devops pipeline deployment product folder device.
To achieve the above object, the present application also provides an electronic device, including:
A processor;
a memory having stored therein executable instructions of the processor;
Wherein the processor is configured to perform the method of remotely deploying an artifact folder using a recursive function as described above via execution of the executable instructions.
To achieve the above object, the present application also provides a computer-readable storage medium having stored thereon a program which, when executed by a processor, implements a method for remotely deploying an artifact folder using a recursive function as described above.
The present application also provides a computer program product or computer program comprising computer instructions stored in a computer readable storage medium. The processor of the electronic device reads the computer instructions from the computer-readable storage medium and executes the computer instructions to cause the electronic device to perform the method of remotely deploying an artifact folder using a recursive function as described above.
The application takes the full name of a local product folder and the deployment catalog of a remote deployment server as a first parameter and a second parameter of a recursion function respectively, thereby calling the recursion function to execute the following operations of acquiring the name of the product folder from the first parameter and splicing the name of the product folder behind the second parameter to form the full name of the deployment folder and remotely creating the deployment folder based on the full name, then traversing the files and subfolders under the product folder, splicing the file names of the existing files to the file deployment full name behind the deployment folder and transmitting the files to be files defined by the file deployment full name in the remote deployment server, splicing the names of the existing subfolders behind the first parameter to be used as new first parameter, calling the recursion function continuously to carry out remote deployment on the subfolders. And by analogy, if the folder still exists under the next-level directory, continuing to call the recursive function to process until the deployment of the folder under the lowest-level directory is completed, and at the moment, successfully deploying the folder with the same directory structure as the local product folder under the deployment directory of the remote deployment server. The application provides a brand-new method for deploying folders, which does not need decompression operation, is favorable for avoiding the occurrence of deployment failure and improves the success rate of deployment.
Detailed Description
In order to describe the technical content, the constructional features, the achieved objects and effects of the present application in detail, the following description is made with reference to the embodiments in conjunction with the accompanying drawings.
Referring to fig. 1 to 15, an embodiment of the present application discloses a method for remotely deploying an artifact folder by using a recursive function, which includes:
101. The full name of the local product folder is called as the initial first parameter of the recursive function, and the deployment catalog of the remote deployment server is called as the initial second parameter of the recursive function.
In the present application, the "full name of the product folder" refers to the path of the product folder plus the name of the product folder. For ease of understanding, please refer to FIG. 1, which gives one example of the full name of the artifact folder "/a/b/c", where "c" refers to the name of the artifact folder, "/a/b" may be considered as the path of the artifact folder, and "/" refers to the path delimiter.
"Deployment directory of remote deployment server" refers to a deployment path for deploying folders on the remote deployment server that have the same directory structure as the artifact folders. For ease of understanding, please refer to FIG. 2, which presents one example of a deployment directory for a remote deployment server, in which the deployment directory or deployment path is "/1/2/3".
102. The name of the artifact folder is obtained from the initial first parameter.
After the recursive function is invoked, the deployment job may be executed by the recursive function. In order to facilitate the creation of folders on the remote deployment server that have the same directory structure as the artifact folder, the recursive function will obtain the name of the artifact folder from the initial first parameter (the full name of the artifact folder). For ease of understanding, please refer to FIGS. 1 and 3 in conjunction, wherein FIG. 3 shows the name "c" of the artifact folder obtained from the initial first parameter "/a/b/c" in FIG. 1.
Specifically, in order to facilitate the acquisition of the name of the product folder from the initial first parameter, the path separator is taken as an identifier, and the content behind the last path separator in the initial first parameter is taken as the name of the product folder.
Specifically, when the name of the artifact folder is acquired from the initial first parameter, a path separator separating the name of the artifact folder from its path may be acquired together. In the example of fig. 3, the acquisition is "/c".
103. The names of the artifact folders are spliced behind the initial second parameter to form the full name of the deployment folder, and the deployment folder is created remotely on the remote deployment server using the full name.
After the name of the product folder is obtained from the initial first parameter, the recursive function can splice the name of the product folder to the back of the initial second parameter, so that the full name of the deployment folder is formed. After the full name of the deployment folder is obtained, the recursive function can remotely create the deployment folder by using the full name, namely, create the deployment folder with the full name.
In the present application, the term "deployment folder" refers to a folder corresponding to a local product folder that needs to be deployed at a remote deployment server. The full name of the deployment folder is the path of the deployment folder plus the name of the deployment folder, wherein the path of the deployment folder is the deployment directory (initial second parameter) of the remote deployment server, and the name of the deployment folder is the same as the name of the product folder, so that the full name of the deployment folder can be obtained by splicing the name of the product folder behind the initial second parameter.
For ease of understanding, please refer to fig. 2,3 and 4, in a specific example, the name "c" of the manufactured folder is spliced to the initial second parameter "/1/2/3" to obtain the full name "/1/2/3/c" of the deployed folder, and then the deployed folder with the full name "/1/2/3/c" can be created on the remote deployment server.
104. Traversing the files and subfolders under the product folder, if the files exist, acquiring the file names corresponding to the files and splicing the file names to the back of the full names of the deployment folders to form the file deployment full names, transmitting the files to a remote deployment server and becoming files defined by the file deployment full names in the remote deployment server, if the subfolders exist, acquiring the names of the subfolders and splicing the names of the subfolders behind the initial first parameters to serve as new first parameters, taking the full names of the deployment folders as new second parameters, and calling a recursion function.
After the creation of the deployment folder is completed, the recursive function can execute the traversing operation of the product folder, the file deployment full name is formed by splicing the file names and the full names of the deployment folders for the existing files, then the files can be transmitted to the deployment folder of the remote deployment server based on the file deployment full name to become files defined by the file deployment full name, and for the existing subfolders, the names of the subfolders are spliced behind the initial first parameters to serve as new first parameters, the full names of the deployment folders are served as new second parameters, and then the recursive function can be called again to conduct remote deployment on the subfolders.
For ease of understanding, please refer to fig. 5-14 in this example, all files and all subfolders under the full name "/a/b/c" are traversed, for any file present, the file name "test.txt" corresponding to that file is taken and spliced to the full name "/1/2/3/c" of the deployment folder to form the file deployment full name "/1/2/3/c test.txt", and then the file "test.txt" is uploaded under the deployment folder under the full name "/1/2/3/c" based on the file deployment full name "/1/2/3/c test.txt".
For any existing subfolder, the name "d" of the subfolder is spliced behind the initial first parameter "/a/b/c" as a new first parameter "/a/b/c/d", and the full name "/1/2/3/c" of the deployed folder is used as a new second parameter, and 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 be deployed remotely for the subfolder, i.e., perform the same operations as for the artifact folder:
Referring specifically to fig. 5 to 14, first, the name "d" of the subfolder is obtained from the new first parameter/a/b/c/d ". Then, the name "d" of the subfolder is spliced with the new second parameter "/1/2/3/c" to obtain the full name "/1/2/3/c/d" of the deployment subfolder, and the deployment subfolder with the full name "/1/2/3/c/d" is created on the remote deployment server. Then, traversing the file and grandchild folder under the subfolder, if the file exists, acquiring the file name of the grandchild folder, "test2.Txt", splicing to the back of the full name "/1/2/3/c/d" deploying the subfolder, forming the subfolder deployment full name "/1/2/3/c/d test2.Txt", transmitting the file test2.Txt to the remote deployment server and becoming the file defined by the subfolder deployment full name "/1/2/3/c/d test2.Txt", if the file exists, acquiring the name "e" of the grandchild folder, splicing to the back of the first parameter "/a/b/c/d", using the full name/1/2/3/c/d of the deployment subfolder as the second parameter, continuing to call a recursive function, and completing the deployment of the directory in the remote deployment server at the same level as the lowest level of the directory, if the file is successfully deployed at the same level of the directory.
Specifically, "transfer the file to the remote deployment server and become a file defined in the remote deployment server by the full name of the file deployment" is executed in a scp command.
Specifically, the method for remotely deploying the product folder by using the recursive function is a devops pipeline type method for deploying the product folder. The local product folder is a local folder after devops pipeline construction is successful.
The application takes the full name of a local product folder and the deployment catalog of a remote deployment server as a first parameter and a second parameter of a recursion function respectively, thereby calling the recursion function to execute the following operations of acquiring the name of the product folder from the first parameter and splicing the name of the product folder behind the second parameter to form the full name of the deployment folder and remotely creating the deployment folder based on the full name, then traversing the files and subfolders under the product folder, splicing the file names of the existing files to the file deployment full name behind the deployment folder and transmitting the files to be files defined by the file deployment full name in the remote deployment server, splicing the names of the existing subfolders behind the first parameter to be used as new first parameter, calling the recursion function continuously to carry out remote deployment on the subfolders. And by analogy, if the folder still exists under the next-level directory, continuing to call the recursive function to process until the deployment of the folder under the lowest-level directory is completed, and at the moment, successfully deploying the folder with the same directory structure as the local product folder under the deployment directory of the remote deployment server. The application provides a brand-new method for deploying folders, which does not need decompression operation, is favorable for avoiding the occurrence of deployment failure and improves the success rate of deployment.
Referring to fig. 1 to 16, an apparatus for remotely deploying an artifact folder using a recursive function according to an embodiment of the present application is disclosed, including:
201. The calling module is used for calling the recursive function by taking the full name of the local product folder as an initial first parameter of the recursive function and taking the deployment catalog of the remote deployment server as an initial second parameter of the recursive function;
202. The acquisition module is used for acquiring names of the product folders from the initial first parameter;
203. The splicing and creating module is used for splicing the names of the product folders behind the initial second parameters to form the full names of the deployment folders, and remotely creating the deployment folders by utilizing the full names on a remote deployment server;
204. The traversal processing module is used for traversing the files and subfolders under the product folder, acquiring the file names corresponding to the files and splicing the file names to the back of the full names of the deployment folders to form the file deployment full names, transmitting the files to the remote deployment server and becoming files defined by the file deployment full names in the remote deployment server, acquiring the names of the subfolders and splicing the names of the subfolders to serve as new first parameters after the initial first parameters if the subfolders exist, taking the full names of the deployment folders as new second parameters, and calling a recursion function.
The application takes the full name of a local product folder and the deployment catalog of a remote deployment server as a first parameter and a second parameter of a recursion function respectively, thereby calling the recursion function to execute the following operations of acquiring the name of the product folder from the first parameter and splicing the name of the product folder behind the second parameter to form the full name of the deployment folder and remotely creating the deployment folder based on the full name, then traversing the files and subfolders under the product folder, splicing the file names of the existing files to the file deployment full name behind the deployment folder and transmitting the files to be files defined by the file deployment full name in the remote deployment server, splicing the names of the existing subfolders behind the first parameter to be used as new first parameter, calling the recursion function continuously to carry out remote deployment on the subfolders. And by analogy, if the folder still exists under the next-level directory, continuing to call the recursive function to process until the deployment of the folder under the lowest-level directory is completed, and at the moment, successfully deploying the folder with the same directory structure as the local product folder under the deployment directory of the remote deployment server. The application provides a brand-new method for deploying folders, which does not need decompression operation, is favorable for avoiding the occurrence of deployment failure and improves the success rate of deployment.
The detailed description of the device for remotely deploying the product folder by using the recursive function is detailed in the above description of the method for remotely deploying the product folder by using the recursive function, and will not be repeated herein.
Referring to fig. 17, the embodiment of the application further discloses an electronic device, which includes:
A processor 31;
A memory 30 in which executable instructions of the processor 31 are stored;
Wherein the processor 31 is configured to perform the above-described method of remotely deploying an artifact folder using a recursive function via execution of the executable instructions.
The present application also provides a computer readable storage medium having a program stored thereon, which when executed by a processor implements the above-described method for remotely deploying an artifact folder using a recursive function.
Embodiments of the present application also disclose a computer program product or computer program comprising computer instructions stored in a computer readable storage medium. The processor of the electronic device reads the computer instructions from the computer-readable storage medium and executes the computer instructions to cause the electronic device to perform the method of remotely deploying an article folder using a recursive function as described above.
It should be appreciated that in embodiments of the application, the processor may be a central processing module (CentralProcessing Unit, CPU), which may also be other general purpose processors, digital signal processors (DIGITALSIGNAL PROCESSOR, DSP), application specific integrated circuits (Application SpecificIntegrated Circuit, ASIC), off-the-shelf Programmable gate arrays (Field-Programmable GATE ARRAY, FPGA) or other Programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, or the like. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
Those skilled in the art will appreciate that the processes implementing all or part of the methods of the above embodiments may be implemented by hardware associated with computer program instructions, and the program may be stored in a computer readable storage medium, where the program when executed may include processes of embodiments of the methods described above. The storage medium may be a magnetic disk, an optical disk, a Read-only memory (ROM), a Random access memory (Random AccessMemory, RAM), or the like.
The foregoing disclosure is only illustrative of the preferred embodiments of the present application and is not to be construed as limiting the scope of the application, which is defined by the appended claims.