Deploying Dynamically Versioned Artifacts via grunt-artifactory-artifact and grunt-nexus-artifact

I’m defining the artifact name and version in package.json.  I want to have a build job on a continuous integration server (Jenkins, Hudson, etc.) that deploys versioned artifacts to reference without modifying package.json.  Another project was appending the git commit count after the semver, so I decided to use the same concept.

I’m using grunt-shell to execute the command to get the repo’s git commit count and then calling the artifactory task inside the callback with the dynamic version.

Sample Gruntfile.js

 

var pkg = grunt.file.readJSON('package.json'),
    deployRelease = function (err, stdout, stderr, cb) {
        if (!err) {
            grunt.config.set('artifactory.release.options', {
                publish: [{
                    id: 'com.yourcompany.js:<%= pkg["artifact-name"] %>:tgz'
                    version: pkg["version"] + '.' + stdout.trim(),
                    path: 'build/'
                }]
            });
            grunt.task.run('artifactory:release:publish');
        } else {
            // error handling
        }
        cb();
    };

grunt.initConfig({
    artifactory: {
        options: {
            url: 'https://{artifactory-repo-base-url}',
            repository: 'js-local',
            username: 'admin',
            password: 'admin123'
        },
        release: {
            files: [{
                src: ['**/*', '!**/node_modules/**/*', '!build/**/*', '!**/test/**/*', '!*SpecRunner.html', '!README.md', '!.gitignore', '!**/package.json', '!**/Gruntfile.js', '!**/*.jade', '!**/*.scss', '!graph/**/*']
            }],
        }
    }
});

 

Advertisements

One thought on “Deploying Dynamically Versioned Artifacts via grunt-artifactory-artifact and grunt-nexus-artifact”

  1. You post interesting articles here. Your
    page deserves much more traffic. It can go viral if you give it initial boost, i know very useful tool that can help you, just type in google: svetsern traffic tips

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s