How to change the location where the gerrit hooks are running from? - gerrit

I am running into a problem where my gerrit hooks are being triggered from a different directory,
I have os.getcwd() as the first line in my change-merged hook,it shows as /mnt/data1/STORE/git/project.git depending on the project the hook is triggered from, I want the hook to run from /gerrit_v2/hooks ,how to make this change?where to look for?is there a place to check the hook logs on how it is being triggered?please advise
FYI..I am using gerrit 2.14

You can't change that. Hooks are executed from the root of the repository which triggered them. If you want, you can change the current directory using the "chdir" command.

Related

I want to enable 'Allowsignup' option by default in Jenkins

I have a groovy file that runs at the time of deployment to create predefined admin users for jenkins. I would like to add a logic here that would enable the allowsignup option. By default the option is disabled.
First I tried making changes in the config.xml file hoping that when I'd restart jenkins it would enable the option but that didn't work.
Now I'm suspecting that maybe I need to make changes via a groovy file using the hudson.security.HudsonPrivateSecurityRealm module, but I'm not exactly sure how to go about doing this.
I am also not sure whether this is possible or the option can only be enabled via UI.

Modify notifications on a running build in jenkins

I occasionally want to get notified when a particular jenkins job that is building finishes. Is there any way to do this?
Scripting it through the API would be fine. I already have the jenkins IRC bot that notifies me of many things, so if I could just dynamically modify the running job build, that would be enough to do what I want -- I'm just having a hard time finding how to accomplish that.
AFAIK, you cannot change a job's config while it's running.
Here is an idea: Use a post-build step to check for an external resource status (like a file containing an action by text) and running an action based on the content of the file.
The external file can be modified while the build is running, so when the post-build is executed, it will follow the logic defined based on the content of the file.
I hope this helps.
You can use email notifier, It will send you an email
https://wiki.jenkins-ci.org/display/JENKINS/Email-ext+plugin

Jenkins/Gerrit stream events - job triggered on newly created branch

I am using Jenkins in combination with the Git and Gerrit plugins. I would like to trigger a job on Ref Updated. However, I need to understand if the action behind this event is the creation of a new branch. If it is, then I will execute my shell script, otherwise not.
As far as I understood, this info is available in the Gerrit's event json response, but I do not know how to consume this json object via Jenkins in the first place.
Is there a way to achieve this easily via Jenkins (maybe something in the interface I missed)? Or is there another way to monitor the creation of a new branch while still in the Jenkins/Gerrit plugin environment?
So I just recalled there are a bunch of Gerrit environmental variables which are available to use in the building script,
namely these ones. I will just have to check if GERRIT_OLDREV is equal to 0000000000000000000000000000000000000000 and if so, it would mean the branch is newly created (for reference: here). Here is the picture I attached in full size.

Is there a possibility in jenkins to run build only if something changed (in ClearCase SCM) from last build?

I need to build in jenkins only if there has been any change in ClearCase stream. I want to check it also in nightly or when someone choose to build manually, and to stop the build completely if there are no changes.
I tried the poll SCM but it doesn't seem to work well...
Any suggestion?
If it is possible, you should monitor the update of a snapshot view and, if the log of said update reveal any new files loaded, trigger the Jnekins job.
You find a similar approach in this thread.
You don't want to do something like that in a checkin trigger. It runs on the users client and will slow tings down, not to mention that you'd somehow have to figure out how to give every client access to that snapshot view.
What can work is a cron or scheduled job that runs lshistory and does something when it finds new checkins.
Yes you could do this via trigger, but I'd suggest a combo of trigger and additional script.. since updating the snapshot view might be time-consuming and effect checkins...
Create a simple trigger that when the files you are concerned about are changed on a stream will fire..
The script should "touch/create" a file in some well-known network location (or perhaps write to a pipe)...
the other script could be some cron (unix) or AT (windows) job that runs continually or each minute and if the well-known file is there will perform the update of the snapshot view..
The script could also read the Pipe written to by the trigger if you go that route
This is better than a cron job that has to do an lshistory each time.. but Martina was right to suggest not doing the whole thing in a trigger for performance and snapshot view accessability for all clients.. but a trigger to write to a pipe or write some empty file is efficient and the cron/AT job that actually does the update is effieicnet as it does not have to query the VOB each minute... just the file (or only after there is info on the pipe)..

How can I make a maven plugin to notify build results?

I develop a simple plugin to notify build results to desktop like growl.
https://github.com/kompiro/notification-maven-plugin
Now, I think there are no good way to listen build result event.
I tested two way to listen the event.
a. ExecutionListener from MavenSession#getRequest()
This way is implemented below.
https://github.com/kompiro/notification-maven-plugin/blob/master/src/main/java/org/kompiro/nortification/buildresult/NotificationMojo.java
This way is running well to notify, but there is a problem. It replaced default maven event execution listener.
So, if user add this plugin, there are no maven execution log.
I thought my implementation extends the default event execution listener "ExecutionEventLogger",
But I can't because The constructor of ExecutionEventLogger needs plexus's logger.
I can't get the logger object.
b. use EventSpy
This is not public interface and user must add the plugin to maven.ext classpath.It is not good for user.
How can I listen the event correctly?
Why not just setup a Jenkins server on your local desktop and have it run the tests and notify you?
There is probably a growl-like notifier for Jenkins somewhere, or worst case just get it to sent an email to localhost with the test results. This also has the advantage of keeping historical test results.
If you are using a nice SCM such as GIT then you can set Jenkins up to poll your local checkout as its upstream, so that you check all your commits individually. If using a less good SCM, I would just have the first step of the job copy all the sources from your workspace into Jenkins' workspace so that you can continue to code away without fear of breaking Jenkins' compile phases.
Also I would favour a FreeStyle project with Maven build step to the built in Maven project type (but then that might just be my own personal bias)

Resources