EGit and post-commit hook - eclipse

This is a follow-on to my question at https://stackoverflow.com/questions/10226287/jenkins-git-and-eclipse
I'm trying to get a post-commit hook running which will invoke a Jenkins build. I can create the hook, place it in my native Git (i.e. not EGit) hooks directory and it works as intended. However, I prefer to have the hook running in my EGit environment as I don't want the complexity of managing two Git environments. I cannot, however, establish where I should place the hook in order for it to be picked up by EGit - any ideas?
=================
Answering my own question - seems EGit cannot do this - see here

If all you want is to have a commit start a jenkins build, then just configure the jenkins job to poll the git repository and start a build whenever a change (=new commit) is found.

Related

How to execute a client-side Git hook?

I am having problem while implementing a pre-push hook. The developers need to run a static code analyzer before they push the code to the git repo. But usually they don't and hence break the build.
Thus, I have written a pre-push hook; which is a shell script to execute the static code analysis ( and copied to .git/hooks) directory but it is not working correctly. This has to be a client-side hook but it is not working as expected. And I dont want to implement this functionality in a pre-commit or post-commit hook since I want static code analysis to be done on the developer's machine before he/she pushes the code (and not when he/she) commits the code.
Thus, please provide your insight as to how I can execute a task (static code analysis) on the client machine before git push command.
As #sestus said, hooks need to be set up client-side, they are not part of the Git repository. It makes sense if you consider that Git is a distributed system and hooks can execute arbitrary code.
What you can do is check in the script into the repository (e.g. to $REPO_ROOT/git-hooks/pre-push) and use the build toolchain of your project to set the up a symlink (ln -s ../../git-hooks/pre-push .git/hooks).

I want to create gradle script to checkout the code from gitHub as soon as deveoper checkin to repository.?

I can checkout the code from github using import org.ajoberstar.gradle.git.tasks.*
. But I want to check out the code immediately after code checkined to github repository automatically and deploys it into web server.Is there any plugin to identify the commit history in github repo.Or some other ways to do it.
Two options I can think of:
Use a git commit hook to trigger the gradle task.
Periodically poll git log to check for new commits (you might be able to use gradle's new continuous mode to achieve this)

Git: Automatically Commit on Publish or Restart of Web Aplication

When developing on my local, I would like to automatically commit all outstanding changes to Git every time I republishing my web project in Eclipse. This way I can get a good view of the steps that I took in my development activities. I will of course rebase before pushing to the public repository. I only want to use this for local history.
Some details:
Eclipse
Weblogic 10.3.5
Web Project
I am looking for a solution that will not require me to change the project itself, so any solution that requires changes to my Servlet class, or to the web.xml will not be satisfactory, although I guess I can do that as a last resort.
Additional Information
I have found that there is a Builders section under a project's properties. This can be configure to do whatever I want, but the only options seem to be to ether run it when manually building, during or after a clean (all of which will not commit often enough), or after an automatic build (which happens every time I save a file, making it way too often too be useful).
automatically commit all outstanding changes to Git every time I republish my project.
"Automatically" and "outstanding changes" cannot coexist in the same sentence without some details about the criteria which would define an "outstanding change": an "automatic" process wouldn't know when a change is supposed to be outstanding or not.
That means an "on demand" process might be easier to implement, and call when needed.
Plus the commit message might be important to refine, as it is a big part of having a "good view of the steps that I took in my development activities."
Whatever the Eclipse project is (here a WebLogic one), that process might simply be doing a add/commit through:
EGit commands (manually called through the EGit GUI, in order to fill-in a meaningful commit message)
or a script, and which would allows (if needed) for a post-commit hook to push that commit to a remote hosting service (like GitHub for instance), since the same commit with EGit would not trigger the post-commit hook.
Since this is supposed to be fully automatic, the other approach would be to use an ant script to trigger the "redeploy" of the weblogic app.
See for instance "Weblogic hot deployment during development (like WSSD/RAD)".
That ant script (using a wdeploy ant task) could then make sure the redeploy target depends on another ant target which would commit and push first (like in this gist).

Buildbot fails on reset --hard

Buildbot 0.8.6
Periodically the buildbot would fail getting a particular repository. It does this command:
argv: ['/usr/bin/git', 'reset', '--hard',
'26d7a2f5af4b777b074ac47a7218fe775d039845']
and then complains:
fatal: Could not parse object
'26d7a2f5af4b777b074ac47a7218fe775d039845'.
However, the correct command is actually:
argv: ['/usr/bin/git', 'reset', '--hard', 'FETCH_HEAD']
Not only that. The SHA number used in the failed command is from a different repository.
Anyone knows how to fix this?
Thanks so much.
Update:
We have two repositories. We have a GitPoller watching one of the repositories. I would like to have a build run if the watched repository had a push. However, both repositories are needed for the build. The error specified above occurs on the second, non-watched repository. The SHA number in the error is from the watched repository.
Ok, first, let's make sure we have the right understanding:
You're having problem with one builder, that builds 2 repositories
Each build has two git steps which clone two different repositories
You're polling one of these repositories to trigger builds
There is no other scheduler that is triggering builds (or at least not those that fail that way)
What happens when you're polling a repository to trigger builds is that each new build carries with it the changes that triggered it. The git steps refer to these changes to checkout the correct version. You probably need to use codebases to help the two steps distinguish between changes. Unfortunately, codebases were introduced in 0.8.7, so you should consider upgrading. 0.8.6 is ancient.
If upgrading is not an option, pass alwaysUseLatest=True to the Git() step of the repository that you are not polling. That will force it to always use FETCH_HEAD. Here's my shot at that setup:
f = BuildFactory()
f.addStep(Git(repourl='git://github.com/you/polled_repo.git', mode='copy'))
f.addStep(Git(repourl='git://github.com/you/other_repo.git', alwaysUseLatest=True))

Jenkins build after Eclipse commit on SVN

I'm using Jenkins for CI, I'm trying to establish a build strategy. My point here is to build
after every commit. I saw that I need to create post-commit file in the hooks directory of my
project repository.
The porblem is that I'm using SVN as an Eclipse plugin, so I don't really have a repository,
I'm just using "right click -> Team " on my project to synchronize/update/commit ...
I can't see where to create my post-commit file in order to launch a Jenkins build.
Does anyone kow how to deal with this issue ?
I've seen many posts before, but none of them was helpful !
Thanks
The simplest solution is to use Poll SCM in your Jenkins job and have it look for changes e.g. every 5 minutes. It won't trigger the build instantly on commit, but it will decouple your SVN and Jenkins a bit more.