Siddesh BG's Build Release Config mgmt Blog

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Thursday, 19 April 2012

Using BUILD_LOG_REGEX in jenkins email notification

Posted on 04:10 by Unknown
Jenkins provide 'Email-ext' plugin, which allows to configure every aspect of email notifications.
One of my requirement is to send in mail the build package URL, which is already getting displayed in console output.

I found a token 
${BUILD_LOG_REGEX, regex, linesBefore, linesAfter, maxMatches, showTruncatedLines, substText, escapeHtml, matchedLineHtmlStyle} - Displays lines from the build log that match the regular expression. 

Here is example usage of it
${BUILD_LOG_REGEX, regex="^Build package URL:", showTruncatedLines=false}

This will extract the line starting with "Build package URL:" from the build log and send it through mail.
Read More
Posted in | No comments

Wednesday, 18 April 2012

Using unix find Command to delete files older than a year

Posted on 01:51 by Unknown
One of the boring task is to clean up data when ever disk usage exceeds the threshold limit. Among the many ways do it, here is the simple usage of Unix find command to delete files older than a year.

   find . -type f -mtime +365 -delete

Where -mtime +365 suggests to list files older than 365 days.
or
  find . -type f -atime +365 -delete

Where -atime stands for access time which is when the file was last read.


Some more examples

find . -mtime 0 # find files modified between now and 1 day ago 
# (i.e., within the past 24 hours)


find . -mtime -1 # find files modified less than 1 day ago 
# (i.e., within the past 24 hours, as before)

find . -mtime 1 # find files modified between 24 and 48 hours ago 

find . -mtime +1 # find files modified more than 48 hours ago

find . -mmin +5 -mmin -10 # find files modified between 
# 6 and 9 minutes ago


Usage of -exec option 
Here is the simple use case.
I want to find all the files with the name 'latest' in a directory and I want to run 'ls -l' command on the result, since I want to know whether 'latest' is a directory or soft link.
find . -maxdepth 2 -name latest -exec ls -l '{}' \;
Here the 
  -maxdepth option restrict the search to be conducted 2 levels of directory hierarchy.
The syntax '{}' \; is mandatory, which is tedious.

Read More
Posted in | No comments

Tuesday, 17 April 2012

Using wget to download files recursively from https site

Posted on 07:52 by Unknown
wget is a command used mostly in Linux to download files from web links (http, https or ftp). To download a file, a simple invocation of wget like
  wget http://mylibrary.com/build-kits/rel-2.7.1/prod1/prod1-2.7.1.10.tar
will download prod1-2.7.1.10.tar to the current directory.

To download set of files (ex .tar files) from a secured https site, we need to provide several options to it
  wget --no-check-certificate -r -l1 --no-parent -A.tar http://mylibrary.com/build-kits/rel-2.7.1/prod1/
where
  --no-check-certificate: don't validate the server's certificate
  -r or --recursive: specify recursive download
  -l1 or --level=NUMBER: maximum recursion depth (inf or 0 for infinite).
 --no-parent: don't ascend to the parent directory
 -A or --accept=LIST:  comma-separated list of accepted extensions.
 -nd or --no-directories: don't create directories.

Read More
Posted in linux, unix, wget | No comments

Thursday, 5 April 2012

Ant script to replace tokens (VERSION) in a file (build.properties)

Posted on 04:05 by Unknown
Version of a product ever changes for main releases, SP releases, hotfix releases, etc. We can't hard-code version value in source files. One of the effective solution to tackle this is to use tokens in the place of version values and replace it before the start of build. The most common tool used to make string replacements are scripts written in perl/shell. Though scripts works well, but why to depend on scripts which are closely tied with Unix systems, to perform token replacement operations on platform independent Java build systems. 


 Java builds are usually managed through Ant/Maven. If perl/shell scripts are not stored along with Java build system, then if anyone checkouts only java code from source control, there build may fail due to improper version characters.


Here is an illustration of performing token replacement using Ant script.


Input file: build.properties file with tokens for various version formats like VERSION_UNDERSCORE, VERSION_NODOT, etc

$ cat build.properties
# KMJC Version properties
version=VERSION_NODOT
dot.version=VERSION_DOUBLE
dot.version.double=VERSION_DOUBLE
dot.version.string=VERSION_DOUBLE
underscore.version=VERSION_UNDERSCORE


After string replacement it should become like


$ cat build.properties
# KMJC Version properties
version=40
dot.version=4.0
dot.version.double=4.0
dot.version.string=4.0
underscore.version=4_0


Ant script

$ cat build.xml
<project name="begin" default="must" basedir="." >
        <condition property="noVersion" value="true">
                <not>
                        <isset property="VERSION"/>
                </not>
        </condition>
        <target name="checkVersion" if="noVersion">
                <echo message="ERROR: VERSION property not defined. Supply it through -DVERSION argument" />
                <echo message="ant -DVERSION=version-number" />
                <echo message="EX: ant -DVERSION=4.0" />
                <fail message="version not supplied"/>
        </target>
        <target name="must" depends="checkVersion" >
                <echo> VERSION=${VERSION} </echo>
                <taskdef resource="net/sf/antcontrib/antcontrib.properties"/>
                <propertyregex property="VERSION_UNDERSCORE" input="${VERSION}" regexp="\." replace="_" global="true" />
                <propertyregex property="VERSION_NODOT" input="${VERSION}" regexp="\." replace="" global="true" />
                <echo> VERSION_UNDERSCORE=${VERSION_UNDERSCORE} </echo>
                <echo> VERSION_NODOT=${VERSION_NODOT} </echo>
                <replace file="build.properties" token="VERSION_DOUBLE" value="${VERSION}"/>
                <replace file="build.properties" token="VERSION_UNDERSCORE" value="${VERSION_UNDERSCORE}"/>
                <replace file="build.properties" token="VERSION_NODOT" value="${VERSION_NODOT}"/>
        </target>
</project>

Usage:
  1) If VERSION Variable is not defined. It will fail
      $ ant
Buildfile: C:\cygwin\home\guruss1\ant\build.xml


checkVersion:
     [echo] ERROR: VERSION property not defined. Supply it through -DVERSION argument
     [echo] ant -DVERSION=version-number
     [echo] EX: ant -DVERSION=4.0


BUILD FAILED
C:\cygwin\home\guruss1\ant\build.xml:11: version not supplied

2) Proper usage
   $ ant -DVERSION=4.1
Buildfile: C:\cygwin\home\guruss1\ant\build.xml

checkVersion:

must:
     [echo]  VERSION=4.1
     [echo]  VERSION_UNDERSCORE=4_1
     [echo]  VERSION_NODOT=41

BUILD SUCCESSFUL


Requirement: propertyregex task needs ant-contrib.jar. Download it and place it under lib directory of Ant installation and add the line <taskdef resource="net/sf/antcontrib/antcontrib.properties"/> to build.xml file
 Alternatively ant-contrib.jar can also be placed in directory of you choice and add line <taskdef resource="net/sf/antcontrib/antcontrib.properties" classpath="${ant-contrib.jar}" /> to build.xml

Read More
Posted in ANT | No comments
Newer Posts Older Posts Home
Subscribe to: Posts (Atom)

Popular Posts

  • Solution to Project Euler Problem 10 - Find the sum of all the primes below two million
    http://projecteuler.net/problem=10 Problem The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. Find the sum of all the primes below two mi...
  • Fortify scan automation steps for analyzing c/c++ code (Makefiles)
    I wrote in my previous blog about installing and configuring Fortify client. This blog presents standard steps to automate fortify scan for ...
  • Posting a JIRA bug using Perl Mechanize
    Perl provides modules which can be used as command line browser to automate tasks dependent on web pages. Among them LWP and mechanize are i...
  • jenkins error: java.io.IOException: Authentication method password not supported by the server at this stage
    When I tried to add a node to jenkins/hudson using ssh as launch method, the authentication keeps on failing with the below error. [12/15/11...
  • Unable to resolve target system name - a DNS problem
    I was not able to ping to any machines from my Windows 2003 server. I did following steps to debug & resolve the issue, which was relate...
  • Installing and configuring Fortify on Linux and Windows machines
    Installing Fortify on Linux (RHEL 5 32 bit) Download Fortify archive Fortify-360-2.6.5-Analyzers_and_Apps-Linux-x86.tar.gz and extract it to...
  • Perforce - can't edit exclusive file already opened
    In perforce, whenever a binary file like doc, xls or ppt files are checked out, it is opened in exclusive lock mode. So no other person can ...
  • Perforce and cygwin
    Are you a command-line freak ? Do you want your automated shell scripts to run on Windows ? Do you wish to work with Perforce commands on Cy...
  • Using BUILD_LOG_REGEX in jenkins email notification
    Jenkins provide 'Email-ext' plugin, which  allows to configure every aspect of email notifications. One of my requirement is to send...
  • 0509-036 Cannot load program p4 because of the following errors
    Here is the full description of error ............ bash-3.00# p4 info exec(): 0509-036 Cannot load program p4 because of the following error...

Categories

  • AIX
  • AIX ssh
  • ANT
  • apache
  • appliance
  • awk
  • branching
  • build-failures
  • cgi-perl
  • code-signing
  • commands
  • continuous Integration
  • cvs
  • cygwin
  • DNS
  • Drupal
  • EPM
  • euler
  • Fortify
  • hadoop
  • hpux
  • html
  • InstallShield
  • iptables
  • iso
  • jenkins-hudson
  • Jira
  • kiwi
  • linux
  • Makefile
  • maven
  • Miscellaneous
  • mysql
  • nexus
  • NFS
  • package
  • Perforce
  • Perl
  • php
  • rbuilder
  • rpath
  • rpm
  • rsync
  • Solaris
  • ssh
  • SuseStudio
  • tinderbox
  • unix
  • Visual studio 2008
  • vmware
  • war
  • webserver
  • wget
  • windows
  • xterm

Blog Archive

  • ►  2013 (12)
    • ►  December (1)
    • ►  July (2)
    • ►  April (2)
    • ►  March (2)
    • ►  February (3)
    • ►  January (2)
  • ▼  2012 (43)
    • ►  December (2)
    • ►  November (1)
    • ►  October (4)
    • ►  September (7)
    • ►  August (5)
    • ►  July (4)
    • ►  June (2)
    • ►  May (3)
    • ▼  April (4)
      • Using BUILD_LOG_REGEX in jenkins email notification
      • Using unix find Command to delete files older than...
      • Using wget to download files recursively from http...
      • Ant script to replace tokens (VERSION) in a file (...
    • ►  March (3)
    • ►  February (1)
    • ►  January (7)
  • ►  2011 (23)
    • ►  December (4)
    • ►  November (9)
    • ►  October (4)
    • ►  September (1)
    • ►  June (2)
    • ►  May (1)
    • ►  April (1)
    • ►  March (1)
  • ►  2010 (15)
    • ►  December (2)
    • ►  November (1)
    • ►  September (3)
    • ►  April (1)
    • ►  February (6)
    • ►  January (2)
  • ►  2009 (28)
    • ►  November (5)
    • ►  October (3)
    • ►  September (2)
    • ►  August (1)
    • ►  July (1)
    • ►  June (5)
    • ►  May (3)
    • ►  April (1)
    • ►  February (2)
    • ►  January (5)
  • ►  2008 (20)
    • ►  December (6)
    • ►  November (3)
    • ►  October (1)
    • ►  September (1)
    • ►  July (8)
    • ►  June (1)
Powered by Blogger.

About Me

Unknown
View my complete profile