0

I am new to Jenkins.
I have a scenario where, I have to build my project in two ways.

1) If there is any commit
2) If there is any changes in some particular files.

I have to call different build scripts in each case.

So how i can achieve this??
Is it possible to setup a post commit Hook based on changes in particular files??

I am using Mercurial as version control system

Thanks in advance

Ajith K
  • 593
  • 6
  • 13
  • Seeing you are left without answer, I know that what you are asking is completely possible. Hook yourself to the commit hook (or on the changegroup hook on your build server), and you should have complete access to the mercurial changesets. I suggest python for full control, and read on jenkins to trigger the build. http://stackoverflow.com/questions/1705921/useful-mercurial-hooks – Vince Apr 08 '14 at 11:14

2 Answers2

1

Unlike Git plugin, Mercurial doesn't provide file level polling but you can have Module level polling.

For #1: Install "Jenkins Poll SCM" plugin that will build after every commit
For #2: In your project > Source Code Management > Mercurial > Click on Advanced > Modules (?) -- This will help you to build only for certain module.

You can even do it through a script, I have done it with SVN. If you want to try it here's the logic:

Add a build step >> Execute Shell >>

cd Workspace
a = 'svn up | grep .java'
if [ -z $a]; then
mvn install   --- Something like this

Hope this helps.

Siva Mandadi
  • 3,673
  • 2
  • 18
  • 12
0

Hi thanks for the replays

I solved this issue by checking changes in my file by using hg diff in my build step. I used execute windows batch command as my build step and the logic is like this

FOR /F "tokens=*" %%i IN ('hg diff -r -1:-2 <file_name>') DO SET X=%%i

SET result=false

IF "%X%" NEQ "" SET result=true

IF "%result%"=="true" (

    "commit is in <file_name>, execute the build script for that"
) 

IF "%result%" =="false" (

    "Commit made on other files..so normal build "
)

where hg diff -r -1:-2 <file_name> will give me the changes made to my <file_name> between the current one and one before that

Ajith K
  • 593
  • 6
  • 13