We use Mercurial (hg) for source control with a central repository (each developer has their own local as well). I am trying to set up a hook in the central repo such that it kicks off a Jenkins CI build.
The hook appears in the hgrc file as:
[hooks]
incoming.jenkins = java -jar C:/buildServerJar/jenkins-cli.jar -s http://ctc-jenkins:8080/ -i C:/buildServerJar/id_rsa build "All Working Projects"
[ui]
verbose = True
debug = True
Now, I have tested the command invoked from the hook on the command-line of the machine that hosts the central repository and it works as expected.
However, when I trigger the hook with a push to the central repository, I see the following output:
% hg --repository D:\dev\hg\******\source push W:\Repository\*********
pushing to W:\Repository\**********
searching for changes
adding changesets
add changeset 62784303122b
adding manifests
adding file changes
adding ****/CMakeLists.txt revisions
added 1 changesets with 1 changes to 1 files
updating the branch cache
running hook incoming.jenkins: java -jar C:/buildServerJar/jenkins-cli.jar -s http://ctc-jenkins:8080/ -i C:/buildServerJar/id_rsa build "All Working Projects"
warning: incoming.jenkins hook exited with status 1
[command completed successfully Fri Jul 26 15:24:58 2013]
The server in question is a Windows machine. Any ideas what could be going wrong or how to get more details on the error?
UPDATE:
So I modified the hook to get more info:
incoming.jenkins = java -jar C:/buildServerJar/jenkins-cli.jar -s http://ctc-jenkins:8080/ -i C:/buildServerJar/id_rsa build "All Working Projects" > hg_output.log 2> hg_errors.log
And it says it is unable to locate the jarfile, which is clearly in the location indicated. Makes me wonder if it is a permissions issue. Does anyone know what user account Mercurial runs its hooks under?
Error: Unable to access jarfile C:/buildServerJar/jenkins-cli.jar
Related
We discovered that our Hg repository got corrupted several weeks ago. This corruption seems to have propagated: all clones (the central repo and the user repos) are corrupted, pretty badly, in the same way. I think we could have prevented it if we did verification at that time.
Is there some Hg setting that would cause verification on each push, and prevent push in case of verification failure? I know I could implement it as a hook in Python, but is there maybe a simpler solution?
Is it also possible to do the opposite: make sure the remote repository is verified before pulling?
FWIW, I am on Windows 10 and we are using TortoiseHg.
Update: I've tried creating hooks as suggested by Jordi. Hg now hangs waiting for locks. Here is what I see:
c:\Users\username\test-hook>hg init
c:\Users\username\test-hook>cd ..
c:\Users\username>hg clone test-hook test-hook-clone
updating to branch default
0 files updated, 0 files merged, 0 files removed, 0 files unresolved
# At this point I edited clone repository settings to include
# [hooks]
# preoutgoing = hg verify
#
# Then I created a test.txt file and "added" it via TortoiseHg context menu.
c:\Users\username\test-hook-clone>hg commit
c:\Users\username\test-hook-clone>hg status
c:\Users\username\test-hook-clone>hg outgoing
comparing with c:\Users\username\test-hook
searching for changes
changeset: 0:a61d33af6cdb
tag: tip
user: username
date: Mon May 06 20:32:54 2019 +0200
summary: test file added
c:\Users\username\test-hook-clone>hg push -verbose
pushing to c:\Users\username\test-hook
searching for changes
running hook preoutgoing: hg verify
waiting for lock on repository c:\Users\username\test-hook-clone held by process '16840' on host 'LT407233'
To answer your question, the hook does not have to be written in Python. In the appropriate server's hgrc (either at the repository level or the system level), simply set
[hooks]
preoutgoing = hg verify
preincoming = hg verify
This may significantly slow down all pull and push operations, but perhaps you are willing to sacrifice speed for correctness.
This will result in output like this when a client tries to pull from a corrupt repo:
$ hg clone http://localhost:9000 sample-repo
requesting all changes
remote: abort: preoutgoing hook exited with status 1
and in your server logs, you should see output similar to
127.0.0.1 - - [18/Apr/2019 12:41:09] "GET /?cmd=batch HTTP/1.1" 200 - x-hgarg-1:cmds=lheads+%3Bknown+nodes%3D x-hgproto-1:0.1 0.2 comp=zstd,zlib,none,bzip2 partial-pull
checking changesets
checking manifests
crosschecking files in changesets and manifests
checking files
a#0: broken revlog! (index data/a.i is corrupted)
warning: orphan data file 'data/a.i'
checked 2 changesets with 1 changes to 2 files
1 warnings encountered!
1 integrity errors encountered!
(first damaged changeset appears to be 0)
You can enable a server side option to perform more validation all incoming content, just set the server.validate=yes option on your server.
The simplest way is to enable it in your server global hgrc or in the repository .hg/hgrc file by adding the following two lines:
[server]
validate = yes
This is a server option but you can also use it on the client. It should validate pull too.
(By the way, what kind of corruption are you seeing?)
Hosting Mercurial on a windows box thru IIS.
I have a root directory where I put all of my repos
d:\repos
- ProjectA
- .hg
- hgrc
- ProjectB
- .hg
- hgrc
- ProjectC
- .hg
- hgrc
All of the repos' hgrc files setup the notify extension with:
config =d:\hg\Repositories\NotificationList.txt
That way I have a single file to manage all of the notification recipients, like the wiki describes:
https://www.mercurial-scm.org/wiki/NotifyExtension
But the wiki makes mention of controlling that NotificationList.txt file thru it's own repository? How can I do that? If I create a separate repo at d:\repos\HgNotify and have the NotificationList.txt file in there, users can change, commit and push back, but when the push occurs, NotificationList.txt does not get updated on the hg server.
Is there a way to update that file somehow? Am I missing a key setup on my Hg server? Or do I need to use a post-push hook to deploy that file?
Update 1
I added the details from Tim's answer and I kept getting HTTP 500: Server Error on the push. I finally figure out how to trace the python calls (python -m win32traceutil), and here is what seems to be the problem:
File "C:\Python27\lib\site-packages\mercurial\util.py", line 402, in hgexecutable
exe = findexe('hg') or os.path.basename(sys.argv[0]) AttributeError: 'module' object has no attribute 'argv'
It doesn't seem to be able to find hg.exe.
Update 2
I installed TortoiseHg and rebooted the system. Now I get:
emote: added 1 changesets with 1 changes to 1 files
remote: notify: sending 1 subscribers 1 changes
remote: warning: changegroup.update hook exited with status 1
So that makes be think that it has found the hg.exe, but it is not doing its job, because the file does not get updated
Update 3
Found my solution here: https://stackoverflow.com/a/8023594/698
The command line I ended up using was:
changegroup = cmd /c hg update
I also added:
[ui]
debug=true
To my hgrc. Those two combined gave me a lot more meaningful messages. In the end I saw "Access denied". I gave Users full permission, but I am not sure why giving IUSR full permission didn't work. Something I'll have to dig into at a later time.
On the server repo containing your notification list you need to add a changegroup hook:
[hooks]
changegroup.update = hg update -C
or if you want to ensure the repository is always clean:
[extensions]
purge =
[hooks]
changegroup.update = hg update -C && hg purge --all
I have Hudson 2.1.2 (not Jenkins) and I've set my projects up to poll my Mercurial repository hourly to check for changes. I generated a public key for my hudson user and added it to the authorized keys on my Mercurial server. When doing the hourly poll, sometimes some projects can't poll Mercurial. Here's an example of what I see in the Mercurial Polling Log:
Started on Apr 30, 2012 2:00:30 PM
[workspace] $ /usr/bin/hg incoming --style /opt/home/hudson/jobs/MyProject/workspace/tmp7506244240405638202style --no-merges --rev default --newest-first
remote: ssh_exchange_identification: Connection closed by remote host
abort: no suitable response from remote hg!
Done. Took 5.3 sec
No changes
However, if I click on "Build Now", it sucessfully polls, picks up changes and builds.
Started by user sdoca
Cleaning the workspace because project is configured to clean the workspace before each build.
$ /usr/bin/hg clone --rev default ssh://hudson#my.mercurial.server:22//opt/hg/current/MyProject /opt/home/hudson/jobs/MyProject/workspace
requesting all changes
adding changesets
adding manifests
adding file changes
added 31 changesets with 40 changes to 11 files
updating working directory
5 files updated, 0 files merged, 0 files removed, 0 files unresolved
[workspace] $ /usr/bin/hg log --rev . --template {node}
[INFO] Using bundled Maven 3 installation
[INFO] Checking Maven 3 installation environment
...
<snip>
Any ideas why I get an error on the auto poll?
I have a server which serves a "central" Mercurial repository; the team clones it and pushes their changes up to it via ssh. Hudson is installed on the same server (RHEL 5.5). I wish to trigger a Hudson build whenever anyone pushes to the central Mercurial repository. I also wish to send a notification email upon a push.
In ProjectName/.hg/.hgrc there is the following:
[hooks]
changegroup.hudson = wget http://Server.Name:8080//job/Project_Name/builds?delay=0sec >&2
If I use putty to ssh to this server and then issue the wget command, a build is successfully triggered, so I don't think it's a permissions issue.
Another hook is:
changegroup.notify = /the/path/.hg/hooks/notify
where notify is:
dest='comma separated list of email addresses'
repo="path/to/repository/"
subject="New changesets in $repo"
hg glog -l 10 -r $HG_NODE: | mail -s "$subject" $dest
When I run ./notify directly from the shell, the mail is sent correctly when I am in the central repository's path; if I execute notify from my home directory, the repository is not found and I get an empty email, but at least I get an email. I assume these hooks are just not being run.
What could be getting in the way? What should I check?
Run cd ProjectName; hg showconfig|grep hooks.
I bet your don't see your hooks, if this is exactly what you have:
In ProjectName/.hg/.hgrc there is the following:
Repository-wide hgrc is .hg/hgrc without dot.
We are starting to use Mercurial for source control. We have configured the HGRC configuration file to do an auto update after we push to the "central" repository.
With some PCs we get this error msg:
warning: changegroup hook exited with status -1
HGRC looks like this:
[ui]
username=ADMIN
verbose=true
[hooks]
changegroup = hg update >&2
Later we perform the update manually and everything works right.
I had a very simmilar issue. This finally works now:
changegroup = cmd /c hg update
The bold cmd /c causes cmd.exe to spawn which will execute hg update as we want it to, but now the exit value from cmd.exe will be 0.
Longer Story:
setup: win 2008 server.
mercurial 1.9.3
hgwebdir via plain http, its an internal network
error:
my error was funnily not the -1 as in your case but
"warning: changegroup hook exited with status 1"
Anyway, the update was not performed.
I found out that I can put the hooks into either .hgrc or into hgweb.config the problem was the same here or there. I finally put it into hgweb.config as below, so all repositories are auto commiting, which is way better than having this loose branch all the time. The main reason I wanted auto commit is that the respositories on the vcs & build server hold now the latest version which makes admin tasks often simpler.
[web] push_ssl = False allow_push = *
[collections] c:\Dev\Reps = c:\Dev\Reps
[ui] debug=true
[hooks] changegroup = cmd /c hg update
It might be related with the user actually executing the hook, which might not be the one with the correct privileges.
Do you have a IIS webserver managing your Mercurial repos?
(from the thread:)
From experience with Mercurial/IIS, things I'd recommend trying:
(a) Does running a simple non-HG command work? Permissions on cmd.exe will
affect out-of-process python hooks.
(b) Does a simple hook like 'python -c "import sys; sys.exit(0)"' work?
(c) If you make it this far, can you confirm that the process is running as the
user you think it's running as, with a hook that does something like:
import win32api
username = win32api.GetUserName()
(write username to a file so you can read it)