Why should my build and deployment scripts be separate?

You may ask this question when you notice that every time you build, you also deploy. What’s the point in keeping the scripts separate if they will always be run together? Before listing all of the reasons I can think of, let me tell you about a bug we recently had in our (currently combined) build and deployment script.

The installer for our licensed FogBugz product is created by a single script that builds both the FogBugz binaries, as well as the installer program that includes all of the binaries in a zipped up cab file. The script first copies all of the files that will be needed in the cab to a specific directory, then builds them, then adds everything in the directory to the cab file, and proceeds to build the installer. A developer recently noticed that certain files were not being included in the cab file that should have been. Closer investigation revealed that the step to create those files failed because the tool necessary to build them wasn’t one of the files copied into the directory to be zipped into the cab.

Now obviously, a lot had to go wrong for this to happen. The build didn’t correctly report the failure to build those files. The build tool required was part of the code repository instead of being placed in a common build tools repository. The build tool required was called via a path relative to the code, rather than relative to the build script. But the issue I’m looking at today is that we mixed up steps that were meant for the deployment with steps meant for the build.

In this case, the deployment script was the script that took built FogBugz files and created an installer with them (deploying to a setup program, as opposed to deploying to the web). Because the steps were mixed together instead of strictly separated, the necessary build tool was not at the expected location, and the build failed (silently, unfortunately).

There are obviously less architectural changes we could make that would have helped us identify and fix this issue more quickly - things like reporting all build errors, or calling the build tool with a path relative to the build script, not the code. But separating the build and deployment scripts would have prevented the bug from occurring in the first place.

Keeping the scripts separate has the following advantages:

  1. Bugs caused by mixing deployment steps into the build script go away.
  2. A single build can be used for multiple deployments (to an installer, to a web site, on a dev machine)
  3. Developers can use the build script on their dev machine, instead of doing the build manually or having a separate script that must be kept in sync.
  4. The development team can take ownership of the build scripts, without having to worry about the details of deploying, which can be left to system administrators and release managers.

Are your build scripts crusty and old?

The other day I was trying to get one of our build scripts at work to run on a new build machine we’d brought up. Because all of our build scripts haven’t been actively maintained, they are very much tied to the environment and other hard dependencies of the existing build machine. And so getting them to work somewhere else (without modifying the script) involves a lot of work to setup all of these hard dependencies. It’s good for me to do this so I can get a better understanding of everything our build scripts do, and why they do those things, and what could reasonably be changed.

Anyway, so in this process I got to a step that was failing in the new build machine. It was trying to access an internal Subversion server for some files, but the new machine could not see the server because of our network configuration. Changing the network configuration wasn’t really an option, so at a bare minimum we’d have to make changes to the build script. After puzzling over it for a little while I finally realized that the step in question is no longer used or relevant at all (you probably guessed that when I mentioned Subversion, since we offer a competing product). It might as well be a no-op. Even better, the same step had caused failures on the official build machine in the past, failures which I worked with our system administrator to fix, so that our builds wouldn’t be broken. But we could have just as easily removed the failing step, instead of continuing to maintain rotting script code.

It was humbling to realize I hadn’t found this issue when it broke on the official build machine. But it also made me realize that build scripts must be actively maintained. If they are not, they will rot. When they do, you’ll get random build failures at the most inopportune times, and you won’t have confidence in the fix, or even if the fix is necessary.

In this particular case, it would be easy to fix it (by removing the dead code) and make no other changes to our process. Fixing it will certainly happen. But we really need to “fix it twice”, by going to the root cause and fixing that issue. The clearest way to do that, in our current situation, is to move forward with a plan I already have - to refactor and combine our build scripts so that developers use the same scripts as the official build machine. Once that happens, we can move ownership of the build scripts back to the development team. Because they will no longer be tied to just one “official” build machine, they’ll naturally be fixed and cleaned up by the developers who use them on a daily basis to get their work done. As build manager, I’ll just need to make sure the scripts still work on the build machine.