Saturday, December 17, 2016

Comparing file with Vim

There are many diff tools to compare files like vimdiff, kdiff3, diffmerge, etc, but then why should I use Vim to compare files ? I regularly use diffmerge to compare files, but it hungs while comparing large log files ( for ex. I found it difficult to compare 20MB log file).

Also some time I just want to compare some section of build log, for example I want to compare the successful build log vs failed log at some section of build target. Typically build logs contain time stamp pre-fixed in the beginning and if I compare 2 build logs, almost every line differs between them.

So in such cases I just prefer to view two log files side-by-side using vim using the following vim options


  1. Open log1
    • vi log1.txt
  2. split the screen vertically
    • :split
  3. Switch to the right-portion
    • ctrl+ww
    • You can use this to toggle between screens
  4. Open another file to compare in right-portion
    • :o log2.txt
  5. Two scroll down both sides of the screen together
    • Start with leg-side by typing below option
    • :set scrollbind
    • Switch to right portion and type the above option again
    • To unset this -> :set noscrollbind

Tuesday, December 13, 2016

Programming Jenkins jobs with Job DSL

The Jenkins job configuration can be programmed using Job DSL, instead of manually configuring it for the following advantages

  • Job configuration can be version controlled under tools like GIT.
  • Easily apply modifications to numerous existing jobs, by changing code and re-running DSL
  • It provides the centralised location to view and analyse all Jenkins job config information
What you need to start with Job DSL?
  • Job DSL Plugin
  • Little bit of Groovy language knowledge

Job DSL Plugin

Install Job DSL plugin and then you'll get a new build step, 'Process Job DSLs' under 'Freestyle project'

Usage

You can run DSL code either

1) By providing DSL groovy code directly at 'DSL Script' section. This option is useful while testing your DSL code. In the below screen shot contains DSL instruction for the job named 'build-hyperloop'

 

2) or Store your DSL code in a groovy file (for ex. myjob.groovy) and ensure it is available in the job workspace. Select 'Look on Filesystem' option and provide the location of this groovy code at 'DSL Scripts'

 

Now save and 'Build' this job and it will create a new Jenkins job by name 'build-hyperloop' if not exist or if this job already exists, then it updates the job with this configuration

End to End flow