It's all about the answers!

Ask a question

pre-receive hook fails with RTC - Git integration during push


john norris (20734044) | asked Apr 27 '16, 3:56 a.m.
edited Apr 27 '16, 7:57 a.m.

Pushing commit to server - error of

Repository ssh://git@mint-rtc/opt/git_repos/groovyTest.git

pre-receive hook declined
hooks/pre-receive: 25: hooks/pre-receive: qs+=old_sha1=affa26a084ee600825d7bfa1910b5d6c74776fd0&: not found
hooks/pre-receive: 27: hooks/pre-receive: qs+=new_sha1=bc9ef3284f7f5a93587cad3c9a17ff3921c63a17&: not found
hooks/pre-receive: 30: hooks/pre-receive: qs+=ref_name=refs%2Fheads%2Fmaster&: not found
Invalid arguments main qs

The chunk of code this comes from is

while read old_sha1 new_sha1 ref_name; do
    qs+="old_sha1=$old_sha1&"

    qs+="new_sha1=$new_sha1&"

    ref_name_escaped=`echo $ref_name | sed -r -e 's/\//%2F/g' -e 's/\./%2E/g' -e 's/-/%2D/g' -e 's/_/%5F/g' -e 's/\!/%21/g' -e 's/#/%23/g' -e 's/\&/%26/g' -e 's/\(/%28/g' -e 's/\)/%29/g' -e 's/\*/%2A/g' -e 's/\+/%2B/g' -e 's/,/%2C/g' -e 's/:/%3A/g' -e 's/\;/%3B/g' -e 's/\=/%3D/g' -e 's/\?/%3F/g' -e 's/\@/%40/g' -e 's/\[/%5B/g' -e 's/\]/%5D/g' -e 's/ /%20/g'`
    qs+="ref_name=$ref_name_escaped&"
done

This is running on mint Linux so I changed "qs+=" to "qs=$qs+" and tried again. No longer get the above error message. Instead I get

Repository ssh://git@mint-rtc/opt/git_repos/groovyTest.git

pre-receive hook declined
Invalid arguments main oldSha1s

I echo'd the value of qs and that looks good -

+old_sha1=affa26a084ee600825d7bfa1910b5d6c74776fd0&+new_sha1=bc9ef3284f7f5a93587cad3c9a17ff3921c63a17&+ref_name=refs%2Fheads%2Fmaster&

the script then calls ValidatePush.js which is where the oldSha1s variable is used. And is where it now fails.

So after debugging I noticed that the javescript looks for "old_sha1" but the object has it stored as " old_sha1". So I changed the script and now get to the next problem which is

pre-receive hook declined
NORRIS: got variables affa26a084ee600825d7bfa1910b5d6c74776fd0
bc9ef3284f7f5a93587cad3c9a17ff3921c63a17
refs/heads/master
Invalid input

Ignoring my console.log to show the variables, I can't find anything that outputs "Invalid input".

Has anyone got the fixes to make this work? Is it fixed in RTC 6.0.2 as I am using 6.0.1? I looked at the script in 6.0.2 and it is indentical to the 6.0.1.

Regards,

John

2 answers



permanent link
john norris (20734044) | answered Apr 28 '16, 5:48 a.m.

There seem to be quite a few problems with the node.js code with the git integration.

I still have not got it to work but the I noticed that the user.name value in git config must be a single word, no spaces. So if you have "Fred Flintstone" then the object generated in the javascript code has user = "Fred" and email = "Flintstone". When I amended the commit to change author to single word then that got me to the next problem.

This is that a "gitUser" value is set using the REMOTE_USER env var. But this is undefined. And that gives "Invalid input" error. So not sure how that is set.


Comments
Winston Enos commented Dec 03 '17, 1:09 p.m.

Yeah, same here.

I had to comment out this line and just use a services account authorized in RTC with a contributor license by modifying that line of code in ValidatePush.js and UpdateWorkItemCommitLinks.js. The NodeJS Git Integration tries to calculate the 'gitUser' value for passing in the HTTP call to RTC for authentication, it uses the committer name separately for actually recording who make the commit, so using this workaround should not destroy traceability.

Once 'gitUser' resolves to a valid RTC username (associated with at least a contributor license) and the Git secret key matches it should connect and return 200.

The gitUser issue is particularly painful because IBM's NodeJS scripts don't account for it if it's not available. If the scripts read your REMOTE_USER env variable and it resolves to nothing, the function that reads it actually return null back to the calling function, which causes it to throw an exception but doesn't return a non-zero error code from Node. This bombs out the pre-receive and post-receive triggers but allows the client command to go through anyway.


john norris commented Dec 04 '17, 4:01 a.m.
 The disturbing thing is that I raised this 18 months ago and by the sounds of it still has not been fixed.
The rational solution for RTC/Git integration really does need rethinking.

permanent link
Lucas Pascoal (134) | answered Oct 24 '17, 7:43 p.m.

 Hi,


You can try it:

The issue exists only for Ubuntu OS, as "sh" shell does not find nodegit because from Ubuntu 6.10, the default system shell, /bin/sh, was changed to dash

To make the integration working, we need to change the hooks scripts shell from bin/sh to /bin/bash.

Edit the pre-receive and post-receive hooks file and change the below entries:

#!/bin/sh

to

#!/bin/bash


Source: https://www.ibm.com/developerworks/community/blogs/iotsupport/entry/RTC_GIT_integration_with_nodejs_fails_on_Ubuntu?lang=zh

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.