Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

Is there a way to automatically register Git repositories?

We have a large number (around 50) of git repositories that we wish to link to work items on RTC.
We can go through and do this one at a time, but it is extremely tedious and error prone to add them all this way.  Also, we frequently add new Git repositories that we want to register.

Is there any way to register a Git repository programatically (via the REST or OSLC api maybe?

We're using RTC 5.0.2 if that makes a difference

Thanks

1 vote

Comments

 Did you find a solution for your problem? I am facing the same challenge.



2 answers

Permanent link
Sort of...
The following works for me on 5.0.2 - I have not tested on v6.x.  It will set $key to the git repository key.


#!/bin/sh
jazzRepoUrl="https://localhost:9443/ccm"
projecID=_.....     # UUID of the jazz project area
jazzUserId=ADMIN
jazzPassword=admin
jazzCookiesFile=/tmp/jazzCookies.txt
name=GitRepo
description="A Git Repository"

ownerItemId=$projectId
currentPAItemId=$projectId


# authenticate
curl -v -k -c $jazzCookiesFile "$jazzRepoUrl/authenticated/identity" >&2
curl -v -k -L -b $jazzCookiesFile -c $jazzCookiesFile -d j_username=$jazzUserId -d j_password=$jazzPassword "$jazzRepoUrl/authenticated/j_security_check" >&2

# register...
curl -v -w "\nRESULT=%{http_code}\n" -k -b $jazzCookiesFile -H "Accept:text/json" -X POST "$jazzRepoUrl/service/com.ibm.team.git.common.internal.IGitRepositoryRegistrationRestService/RegisterGitRepository?name=$name&ownerItemId=$ownerItemId&currentPAItemId=$currentPAItemId&url=$url&description=$description" >/tmp/registerOut
key=$(sed -n 's/^.*"key":"\([a-z0-9]*\)".*$/\1/p' /tmp/registerOut)
if [ "$key" = "" ] ; then
    echo "FAILED"
    cat >&2 /tmp/registerOut
    rm -f $jazzCookiesFile /tmp/registerOut
    exit 1
fi
rm -f /tmp/registerOut

# set commit uri format
curl -v -w "\nRESULT=%{http_code}\n" -k -b $jazzCookiesFile -H "Accept:text/json" -X POST "$jazzRepoUrl/service/com.ibm.team.git.common.internal.IGitRepositoryRegistrationRestService/updateRegisteredGitRepository?repoKey=$key&name=$name&description=$description&url=$url&ownerItemId=$projectId&configurationData=%7B%22com_ibm_team_git_config_use_repository_process_area_unmapped_refs%22%3A%22true%22%2C%22com_ibm_team_git_config_commit_url_format%22%3A%22%24repo%2Fcommit%2F%24sha1%22%2C%22com_ibm_team_git_config_git_server_credentials%22%3A%7B%22userId%22%3A%22%22%2C%22encryptedPassword%22%3A%22%22%7D%7D" >&2

rm -f $jazzCookiesFile

echo $key

1 vote

Comments

 Amazing... Let me check it out.

 what does $url stands for?

Sorry, was copying lines out of a much longer script and missed that one :)
$url is the URL of the git repository, something like https://github.com/rickettm/repo

1 vote

 Thanks. I am almost done in porting your code to work on 6.0.2. Will post here the final code.

 Hi Michael and Liora,

I am trying to do the same for 6.0.6 But I am not able to register. Getting the below error

{
    "errorClass""java.lang.IllegalArgumentException",
    "errorMessage""\"The method 'GitRepositoryRegistrationRestService.postRegisterGitRepository()' has been supplied with an illegal argument\"",
    "errorCode"400
}


Permanent link

In newer CLM version you can do it automatically using the script provided by CLM team. Please refer to Registering and updating Git repositories by using scripts document.

0 votes

Your answer

Register or log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,941
× 97

Question asked: Mar 08 '16, 6:50 a.m.

Question was seen: 4,352 times

Last updated: Jan 22 '20, 4:41 a.m.

Confirmation Cancel Confirm