Wednesday, October 16, 2013

Tag a Mercurial repository from within Grunt!

grunt.registerMultiTask('executerepotagging', 'tag a repository', function() {
   var done = this.async();
   executerepotagging = grunt.util.spawn({
   cmd: "hg",
   args: ["tag",
      "-u build",
      "v" + global['version']]
   }, function(error, result, code) {
      if(code == 127) {
         return grunt.warn(
            'The attempt to push a tag failed. '
         );
      }
      done(error);
   });
   executerepotagging.stdout.pipe(process.stdout);
   executerepotagging.stderr.pipe(process.stderr);
   executerepotagging = grunt.util.spawn({
      cmd: "hg",
      args: ["push"]
   }, function(error, result, code) {
      if(code == 127) {
         return grunt.warn(
            'The attempt to push a tag failed. '
         );
      }
      done(error);
   });
   executerepotagging.stdout.pipe(process.stdout);
   executerepotagging.stderr.pipe(process.stderr);
});
grunt.registerTask('tagrepo', 'executerepotagging');

 
 

"Up top" inside grunt.initConfig({ is:

executerepotagging: {
   main: {
      src: [],
      dest: 'tagrepo',
      options: {}
   }
},

 
 

If you run this locally from the command line you will likely be prompted for a username and password when attempting the push. Clearly, this will not do in an automated process. The request for a username and a password will act link a kink in a hose and sabotage the push.

You cannot spec a username and a password at the push command, but there are, of course, ways to save credentials for Mercurial. One is making a mercurial.ini file at the build server at C:\Program Files\Mercurial which looks like so:

[extensions]
fetch=
purge=
mq=
extdiff=
[auth]
kiln.prefix = http://jenkins.example.com/whatever
kiln.username = god
kiln.password = iamsuper

 
 

In Jenkins, for example, one would specify a Mercurial repository url under Source Code Management and here the path needs to match up with what is in the .ini file in a case-sensitive manner.

No comments:

Post a Comment