Tuesday, 26 June 2012

rsync - Syncing soft-link's as soft-link

We were running rsync between 2 repositories (created on Linux OS) from many days. But we missed to handle soft-links properly. The option 'l' provided by rsync will update the soft-links in the destination server accordingly. If this option is not provided, in the destination, the directory pointed by source will be created with the soft-link name and it will be never updated at all !


Here is a usage of rsync
/usr/bin/rsync -avuzl --stats /export/kits/dpm/builds/dev/rkm root@us-repo.org:/export/kits/dpm/builds/dev


Where the options
 -a, --archive               archive mode;
 -v, --verbose               increase verbosity
 -u, --update                skip files that are newer on the receiver
 -z, --compress              compress file data during the transfer
 -l, --links                 copy symlinks as symlinks

Friday, 8 June 2012

Deploying maven build artifacts to Nexus repository

To deploy the artifacts generated by your maven build to nexus repository, you need configure it in 2 files
1) Parent pom.xml
2) settings.xml

and also to prevent publishing password in settings.xml file, you need to configure password less ssh connection between your build machine and nexus repository


Pom.xml changes
Add distributionManagement section to your parent pom.xml and provide ID, name, url for various delivery types like snapshots, releases, site, etc.
Here is an example from our project




<distributionManagement>
   <repository>
<id>kms.distribution.releaserepository</id>
<name>DPM KMS Maven Release Repository</name>
<url>scp://my-repo.org/export/nexus/sonatype-work/nexus/storage/releases/</url>
<uniqueVersion>false</uniqueVersion>
   </repository>
   <snapshotRepository>
<id>kms.distribution.snapshotrepository</id>
<name>DPM KMS Maven Snapshot Repository</name>
<url>scp:// my-repo.org /export/nexus/sonatype-work/nexus/storage/snapshots/</url>
<uniqueVersion>false</uniqueVersion>
   </snapshotRepository>
           <site> 
            <id>kms.distribution.sitelocation</id>
            <name>DPM Maven Site location</name>
            <url>scp:// my-repo.org /export/nexus/sonatype-work/nexus/storage/rkm/site/</url> 
            </site>
</distributionManagement>

The above configuration dictates to copy kits using scp. There are other ways of delivering like http.
Also we created ID's like kms.distribution.releaserepository, kms.distribution.snapshotrepository, etc. The related entries needs to be made in settings.xml file

settings.xml changes
The settings.xml for a maven2 project can reside either in
1) ~/.m2/settings.xml or
2) MAVEN-INSTALLATION-LOCATION/conf/settings.xml

In settings .xml file add  <servers> tag and provide login credentials for nexus repository.

 <servers>

   <server>
        <id>kms.distribution.snapshotrepository</id>
        <username>maven</username>
    </server>
    <server>
        <id>kms.distribution.releaserepository</id>
        <username>maven</username>
    </server>
    <server>
        <id>kms.distribution.sitelocation</id>
        <username>maven</username>
    </server>

  </servers>


You can provide password using <password> tag. But it's not wise to share password in settings.xml.
Instead establish a password less ssh connection between your build server and nexus repo using public/private key generation.


After making above changes, run
mvn depoloy

which will deploy your artifacts in nexus repository.