Introduced
If there's one thing that software developers are good at (not quoting the movie "hacker"), it must be automating tasks that usually need to be done manually. Getting the computer to deal with tedious tasks will make life easier, and we're talking about getting people to focus on what they care about. However, the research team often ignores the most helpful audience-themselves.
In a large number of small and medium sized software workshops, there is no automated build and release tool. Building, staging, and code publishing are all done manually, as well as running tests, backing up older versions, tagging new versions, and many other things that are repetitive. After all, you might think this is all very simple work, the integrated development environment through the button or shortcut key to build the project, you open two windows drag and drop a little file or folder to complete the site release. But when you're maintaining the code base and applying all these things together, here a few minutes, a few minutes there, will end up wasting a few hours.
Fortunately, it is easy to solve the problem. The basic automated building plan is easy to deploy, highly customizable and inexpensive. This article describes some of the motivations for building an automated process, and some concepts you will need to contact. The second part of this series describes the. NET solution, but these technologies are applicable in any environment.
What problems are we trying to solve?
Before we go into it, let's look at some of the problems we're trying to solve. Not all of these problems exist in your organization, but if you look closely at your team, you will find some of the problems that may exist, and it is likely that the rest of your build process may take some work.
Inconsistent builds: Writing code in an integrated development environment is a wonderful thing. However, there are costs, such as frame/runtime versions, output structures, compilation/debug builds, configuration settings, environment variables, and compilation options that are typically handled by the integrated development environment or the operating system. It seems like a good thing, but unless you use the exact same development machine, if developers don't pay attention to these details, the same code base, different developers will get different output.
Incomplete builds: Most of us have ever felt guilty about bad source control practices. We may have forgotten to submit a bug fix, or forgot to update the latest code before compiling to get other people's changes. When these occur in a human-built environment, the code that is about to be released is not up to date. We need a solution that guarantees that you will always be released in the source control system.
Failed unit tests: unit testing is an integral part of any good application and, if used properly, helps avoid introducing new bugs while fixing bugs. However, the light writing test is far from enough. You have to perform all the tests on a regular basis, and it's easy to forget when something needs to be handled by yourself. No one actually performs these tests, so maybe some unit tests don't pass and you never know.
Human error: Even the simple process of careful planning is prone to human error. We've all had fingers hovering on the keyboard, accidentally knocking the buttons, or accidentally removing the OS kernel (which happens more often than you think). Or at 1 o'clock in the morning, when sleepy, we accidentally opened the official server as a test machine. This is unavoidable because nobody is perfect, so anything can go wrong once human interaction is needed.
Security: The security of servers and networks is always handled by a separate software team. There are usually two extremes, or there is a limit to the server connection, which is not accessible to anyone, it takes one months to train new employees, or if the server is open to everyone, malicious clicks from any member of your team can bring down the system. As a developer, I usually prefer the second option, because I can actually do it well, but I see the danger of doing it. Regardless of where your organization is in the field, automation will only improve your process.
What do we need to do first?
Once you have identified the main pain points of the team, you can design the solution for your needs. There is no universal plan. As long as you have automatic construction, it can reduce human operations and make things consistent, you are moving in the right direction.
However, you really need a lot of things.
You have to start contacting good source control practices. Whether you're using SVN, Mercurial, Git, or TFS (do not use SourceSafe), you need to define such things as branching strategies, how to handle third parties and internal libraries, and how to organize projects in warehouses. Of course, your team has set sail. When someone does something in a small project and does not follow the rules, they can screw up the whole process.
You must have a developer as an automated build engineer. This person will be responsible for writing build scripts, building a continuous integrated development environment, and probably also responsible for the construction and deployment of the source control system. Unless you have a large and complex environment, the work should take up only a fraction of his time, so he can do regular development work most of the week.
Even if you want to never use it, there should be a contingency plan in the process, like other mission-critical programs in your organization. Compiling a server is likely to become a single point of failure, it is likely not to have load balancing capabilities, and there will be no hot backup to prevent server downtime. In this case, you want to make sure that you can quickly build a new server, complete configuration and permissions settings, and should have a plan B that does not use the build server. Although the goal of the realization is never to do anything by hand, it should always be guaranteed to be feasible.
Build Scripts
The automation of the build process relies on simple repetitive tasks. The first step is to write the build script. The build script can be any form: Batch file/shell script, xml-based task set, self-written configurable program, or any combination of them. In the. NET world, MSBuild is a command-line feature provided by Microsoft, which uses xml-based project files to build Visual Studio solutions. Nant is another common. NET Build scripting tool, similar to the popular Java tool Ant. Others include rake in the Make,ruby common in the open source community.
No matter how you choose to write your build script, you should find a way to fit in and stick to it. For example, once you find the best way to build a Web program, creating a build script for a new Web application should be easy, as long as you copy the script from other projects, modify the partial name and path.
The implementation of the operating system and the programming framework is clearly different, but the idea is basically the same. The script should complete everything you normally do when building/compiling/delivering the preparation environment. Typically, this means compiling the code, using specific compilation options, and saving the output file separately from the original code base for deployment. Even in projects that do not need to be compiled, static web sites, for example, may have content that is not dynamically updated, such as a test page or debug script, and you want to manage the content uniformly in the source control system, but when you do want to deploy, the build script will not release the file when it is delivered to the environment. So you don't have to think about these things every time.
In addition to the basic build/compile/delivery preparation environment, you can actually do whatever you want. Want to compress JavaScript files? Create a task for it. Need a unique timestamp in code before compiling? Create a task. In order not to allow the site to fall into the opponent's bag, the need for data encryption algorithm? Add a task (ask someone to help). In the build process, what you can do at the command line can be performed before and after the code is compiled.
Most software projects have more than one module. For example, you might have a Web application, but you also have a separate database, which is part of the overall solution. For this scenario, a single control script is a workaround. The script is a controller that calls a single script at a time. There are scripts in every Visual Studio project, Java package, or custom code structure. Each individual script has a specific task for the project, and the control script contains all the shared functionality.
Make the script as generic and reusable as possible. Using a relative path, do not use an absolute path, the information for the specific project is defined in one place, and the reusable information is defined in the control script. This is easy to maintain and helps build new projects in the future.
Continuous integration
Once the script is written, the project can complete the compilation and delivery of the preparation environment through a single command. This is a good start, but someone needs to execute the order. Our goal is to get rid of human intervention, so continuous integration will consider these for us.
As for the build script, there are many different technologies to choose from, and the project is organized in a variety of ways. But again, you're going to want to find a solution that's right for you and stick with it to keep it consistent in your project.
Some popular options are teamcity, Jenkins, CruiseControl (or cruisecontrol.net), and if you prefer a multipurpose application, Microsoft team Foundation In addition to source control and build, server can complete continuous integration. Each product has its own target audience, but they are all designed to monitor the source code and run the build script automatically, so there is no need to do this manually. The traditional strategy for continuous integration servers is to monitor the changes in the source control warehouse, automatically download the latest code when there is a change, and then execute the script, which compiles the application and prepares the publication in turn. However, in the build script, you can add any tasks or behaviors you need.
You can set up unit tests or any other automated tests you write to perform as part of the process. Once someone submits the code, the test runs immediately. As for the test not to pass, even if the compiler does not pass, you will be told that the error, so these problems can be quickly processed. As far as I am concerned, I suggest shooting the responsible person with darts (dunce is another good choice), but it is up to you to decide how to achieve it.
Release
So far everything has been for this moment. At the moment we are just submitting the code, automatically compiling, running the test, delivering to the preparation environment and ready for release. The final step is to publish the code for the staging environment to wherever it is needed.
Publishing your own hosted Web applications typically copies files from the preparation environment to the Web server. This could mean manually copying files or organizing them into a simple batch/shell script. Because we're still trying to make life simple and automated, you're looking for a better solution. Depending on your organization's security strategy, you may be able to organize tasks within the continuous integration process to copy files through the file system or FTP. As for a pure HTTP solution, you can look at products such as Dubdubdeploy, which are not restricted by domain security or file system access, and can copy files between servers.
If you have a packaged product, the final step is simply to package the product. The build script may have handled the creation of the installation package, the organization of documents, and other things related to the release of the file. Now that you have a deployable product, the rest is to copy the product to a 3.5-inch floppy disk, package, and publish.
Summarize
Building an automated build environment may take some time to get it to work the way you want it to take at least a few days, maybe a few weeks, and perhaps adjust as you wish. Finally, you need to weigh the time that will be saved each day, and the traps that can be effectively avoided when you are in a consistent process and are easily dropped.
When everyone is doing what they do best, your organization will be the most efficient. Developers write code, build engineers to handle build and deploy configurations, build servers to do all the repetitive tasks, and it does a great job. Running a smooth software process usually directly improves product quality and shortens the release cycle, both of which will greatly affect your company's financial position.