Jenkins Job to Automate SVN Tagging

In my previous post, I gave a high-level overview of a Jenkins job that could automate creating SVN tags.  In this post, I’m going to give more details on exactly how this is done.

Step By Step

This job makes the assumption that the tag is always created from the trunk.  Now obviously, this isn’t ideal in all cases.  Modify it to fit your needs.

If any build steps are not available to you, this means you likely need to install a plugin for Jenkins.

  1. Create a Freestyle job.
  2. Create parameters for the following:
    1. SVN username (string parameter)
      SVN User
    2. SVN password (password parameter from the mask passwords plugin)
      SVN Password
    3. Version number of the tag
  3. Set the base path to your repo as an environment variable in the Jenkins jobPrepare Environment for the Run
  4.  Make sure you mask the SVN_PASS parameter
    Mask Password
  5. Add a shell build step (this is assuming Jenkins is running on a Linux server)

    1. The version tag will be consistent every time.  This allows you to put other text along with your version, such as “v” 1.0.0 or MyProject-1.0.0 depending on how you want your naming scheme.
    2. Both from and to use the BASE_PATH that we set as an environment variable.
    3. We finally do the copy using several variables we have previously defined.

Make sure the SVN package is installed on your build server.

And there you have it!  How simple is that?  Instead of having to run the command every time, you can click the “Build with Parameters” button in Jenkins, type in a few parameters, then the tags will be created the same way every time.

While this may not be very powerful, consider adding the following features (would not take that much extra effort) to make it a lot more powerful:

  • Instead of assuming we copy from the trunk, make that another parameter.  That way it can copy from anywhere to a tag.
  • Rather than forcing the user to input the version, make the argument instead point to a path within the project that holds the version file.  That way the tag automatically grabs the version from whatever is in the project.  OR make this job automatically increment the version every time!
  • Make this job run a suite of tests before the tag is created.  If the tests don’t pass, the tag isn’t created!

The options are endless… but hopefully this gives you just a taste of how powerful using automation with Jenkins can be.  Creating something like this took me maybe an hour or two.  If you invest time into learning Jenkins, it won’t take you long to create jobs like this one.  Then every time you or someone that’s much, much less experienced on your team can perform this operation by clicking a few buttons and filling out a form.

Now the next time a ‘fire’ comes and you must quickly create a new tag based on your new hot bug fix, you can just click a few buttons to create your next release tag.

Please follow and like us:

Leave a Reply

Be the First to Comment!

Notify of