We are using Jfrog Artifactory and looking for a way to automate the Repo, Group and permission creation for a list of items as part of a Azuredevops pipeline.
For example, I want to create a virtual Repo called "myproject-mvn-repo" with all its subcomponents as below.
- create a virtual repository: myproject-mvn-repo
- link existing or create remote repo for maven (if not existing): myproject-mvn-remote-repo
- Create 2 local repos if not existing :- myproject-mvn-release-local-repo - myproject-mvn-snapshot-local-repo
- Create a security group for the Repos: - myproject-sg
- Create 2 type permission for the Repos and related builds : myproject- developers (read write) myproject-contributors (read/write/manage)
- Add users to the group subsequently
I tried to follow the Jfrog document , but couldn't loop through for a number of items and would need to make it as idempotent(shouldn't create/modify any repo or component if already present)
Let's split it into 2 parts - managing repositories, and managing permissions.
Repositories
In order to create / update / delete multiple repositories in a single request you can use the Artifactory YAML Configuration.
For example (simplified):
Note - this is a
PATCH
request, which means that if a repository already exists it will not fail the request, but it will update its configuration based on the settings in this request.Permissions
For managing permissions there are also two options - using projects (preferred), or using groups and permission targets.
Using Projects
From the documentation:
You can create projects, assign roles to users and groups in projects, assign repositories to projects, and more. Projects can be managed using REST API, specifically (but not limited to):
Using Groups and Permission Targets
Manage groups using REST API. First try to create a group. If a group already exists it will return a
409 Conflict
, then use update group instead, or just add / remove members to the group.For example - create group
myproject-developers
withalice
andbob
as members (simplified):Manage permissions - use REST API to create / replace permission targets, aggregating the repositories and granting each group its relevant permissions on those repositories.
For example (simplified):