Pages

Wednesday, December 22, 2010

SVN Pre-commit hook failed - jira-client.py throws error

SVN Pre-commit hook failed - jira-client.py throws error

We recently upgraded our Atlassian Products (crowd, Jira, fisheye, crucible), particulary Jira from 4.0.1 to 4.2.1

Since this upgrade we could not do SVN commits. It keeps on failing and gives this message:

Problem:

svn: Commit failed (details follow):
svn: 'pre-commit' hook failed with error output:
Committer: pdhawale
Commit message: "SUITE-XXXX - Audit History changes"
Commit rejected: Unable to connect to the JIRA server at "http://xxxx.xxxxxx.co.nz".



Then I did some digging in the my SVN-server folder and found out that there is a python script for JIRA Commit Acceptance Plugin. This script gets run when we do SVN Commits. The error was thrown from this python script.

JIRA Commit Acceptance Plugin:
This plug-in lets you define certain basic rules that will determine whether a commit to your version control system will be accepted based on the issues in JIRA. For example, you can define a rule that no commit will be accepted unless it contains a valid issue key. Or you can set a rule that no commit would be accepted if the issue was not in an "open" state.
For more information go to JIRA Commit Acceptance Plugin

The python script is called jira-client.py and it is located in this location: {svn-server}\repo\hooks
In case you are using perl, The perl script is called jira-client.pl and it is located in this location: {svn-server}\repo\hooks

Solution:

JIRA Commit Acceptance plugin is not part of the Standard Jira Package. So, whenever you install or upgrade your Jira Application, you will need to explicitly (or you can say 'manually') install this plugin every time.
For more information on installation steps go to JIRA Commit Acceptance Plugin

So, the jira-client.py is one part of the JIRA Commit Acceptance plugin, The plugin adds an extra remote method that the jira-client.py script is trying to call, but because the plugin isn't installed yet, there's no remote method for the script to connect to and thus it fails and throws the error mentioned above.

You should be able to install the plugin (its free) in your JIRA server and everything should work again. You may want to double-check within JIRA that the plugin is configured properly though, as I'm not sure if the settings are kept as part of an XML backup or not.

Also, you will need to configure JIRA access and svnlookup path in the new jira-client.py for your SVN-server, as follows:

# configure JIRA access
# ("projectKey" can contain multiple comma-separated JIRA project keys like "projectKey = 'TST,ARP'".
# If you specify multiple keys, the commit will be accepted if at least one project listed accepts it.
# Or you can specify "projectKey = '*'" to force using the global commit acceptance settings if you don't
# want to specify any exact project key.)
jiraBaseURL = 'http://xxxx.xxxx.co.nz'
jiraLogin = 'xxxx'
jiraPassword = 'xxxx01'
projectKey = '*'

# configure svn lookup path
svnlookPath = 'D:\\svn-server\\bin\\svnlook.exe'



Also, please edit your new pre-commit.bat file to look at the python installation location as follows:

@c:\\Progra~2\Python25\python.exe D:\\svn-server\\repo\\hooks\\jira-client.py %1 %2



Quick Work Arround Available:

If you do not have enough time, as your Jira is already in production and people want to commit their work urgently. Then disable the SVN check on Code Check-in,  as follows:
Comment out the code in your existing jira-client.py


## invoke JIRA web service
#xmlrpcUrl = jiraBaseURL + '/rpc/xmlrpc'
#try:
#    s = xmlrpclib.ServerProxy(xmlrpcUrl)
#    acceptance, comment = s.commitacc.acceptCommit(jiraLogin, jiraPassword, committer, projectKey, commitMessage).split('|');
#except:
#    acceptance, comment = ['false', 'Unable to connect to the JIRA server at "' + jiraBaseURL + '".']

#if acceptance == 'true':
#    print >> sys.stderr, 'Commit accepted.'
#       sys.exit(0)
#else:
#    print >> sys.stderr, 'Commit rejected: ' + comment
#    sys.exit(1)



And put this line AFTER the commented lines shown above:

sys.exit(0)


This should then disable the SVN check on Code Check-in and you would be able to commit the code changes. The only problem with this quick fix is that, user is able check in the code changes without any Jira Issue key or comment.

I could not find a good solution that would tell all this to me and I had to spend one whole day to figure out what is wrong.. I hope this blog helps you and save some time for you.

No comments:

Post a Comment