AKS
AKS

Reputation: 17306

Command line: Create new repository(group) / a repository(project) inside an existing repo group in RhodeCode (uses Hg Mercurial)

I'm looking for a way to create a new repository "newrepo" and a new project "newproject" in RhodeCode using command line way (instead of using RhodeCode Browser based GUI clicks).

RhodeCode version is 2.2.5 and it got all repositories/projects (after we migrated from Hg Mercurial to RhodeCode interface). Everything works great for the migrated projects or if I create a new repository/project inside an existing repository manually using RhodeCode GUI interface.

Now, I want to do create a new repository / project using a command line CLI/API way so that I can automate the repository/project creation process (from Jenkins).

I searched a bit and found that I have to use the following link but couldn't find an easy example on how to actually run it: https://docs.rhodecode.com/RhodeCode-Enterprise/api/api.html#create-repo

Has anyone of you tried to create a new repository in RhodeCode using a Shell script or groovy etc? Thanks.

PS: I'm not looking for creating a new Hg/Mercurial repository (hg init, then hg push / hg pull etc).

Automation I'm trying would do this:

  1. Create a new repo / project or a new repository group then repository in it. Probably grant some access to a set of users/groups or create one etc. Also create an empty README / DELETE_ME_ANYTIME file automatically.

  2. Once the above is created, then I'll create a project structure locally on my machine and perform hg push to the above mentioned newly created repository/project or repositorygroup/repository whatever you call it.

    hg clone http://[email protected]:8010/newrepo/newproject

    hg add README # add first file

    hg commit -m "Initial" # commit with message

    hg push # push changes back

  3. Auto create Jenkins build / etc jobs and auto launch the first build and be done with it.

I know how to do bullet 2, 3 automatically (using template job formats etc, in Jenkins and running Maven/Gradle build to build the project) but the 1st bullet is what I'm trying to find, how to do at command line?

For bullet 1: I found this.

rhodecode-api

The RhodeCode API lets you connect to RhodeCode Enterprise and carry out management tasks, for more information about the API, see the API Documentation. To pass arguments on the comamnd-line use the method:option syntax.

Example usage:

# Run the get_repos API call and sample output
$ rhodecode-api --instance-name=enterprise-1 create_repo repo_name:brand-new repo_type:hg description:repo-desc
{
  "error": null,
  "id": 1110,
  "result": {
    "msg": "Created new repository `brand-new`",
    "success": true,
    "task": null
  }
}

Upvotes: 0

Views: 733

Answers (1)

marcinkuzminski
marcinkuzminski

Reputation: 1771

Your solution using our api helper is the best. I would also recommend using auth-tokens for jenkins API calls, as well as the push operations. You this way have much more control over the credentials, and auth-tokens can be easily revokable. They work in similar way as googles application-specific passwords.

Upvotes: 1

Related Questions