Question

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

Was it helpful?

Solution 2

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

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top