I am writing a script to automate the production of some trigger tokens for some projects in gitlab.
The script starts with a call to the gitlab group api:
curl --header "PRIVATE-TOKEN: ${PRIVATE_TOKEN}" "https://gitlab.com/api/v4/groups/12345 | jq > projects.txt "
This creates a list of projects.
Some projects are missing from this list. I know they are missing because I can see these missing projects via the gitlab web interface and they are clearly listed as part of my group (id = 12345; this is a dummy id for the purposes of this question).
Further, a call to the projects api for each specific missing project (using the same PRIVATE_TOKEN) successfully returns complete information about those projects.
Any input would be much appreciated!
Thanks,
Luke
You have to use pagination with the GitLab API to get complete results beyond the max page size.
Also note that if you have projects organized into subgroups, the Group List Projects API has a include_subgroups option (default false) that will need to be provided if you also want to list projects contained in subgroups.
Related
For the three vcs supported by circleci, we have observed that for GitHub and BitBucket we are able to access all the endpoints through Postman where the project sulg in the URL is prepared with the "Project Name". Whereas in case of GitLab, the project slug takes "Project ID" instead of the "Project Name" and we could not find the GitLab "Project ID" programmatically through circleci endpoints.
Please help us if there is any way we can get the GitLab Project ID programmatically.
We tried the Organization Summary Metric endpoints but could not find the Project ID in the response.
Whereas in case of GitLab, the project slug takes "Project ID" instead of the "Project Name" [...]
It's a project identifier rather than the actual project ID; the project identifier can be seen in the URL of the pipelines page for a given project, along with the organization identifier (this one too is different from the actual organization ID).
For example, if you go to the pipelines page of a specific GitLab-based CircleCI project, you'll see the URL has the following format:
https://app.circleci.com/pipelines/circleci/<organization_identifier>/<project_identifier>
In your API calls related to GitLab projects, you can still use a that follows the format <vcs>/<org>/<project>. The difference with GitHub/Bitbucket orgs/projects is that for GitLab:
<vcs> is always circleci
<org> is the organization identifier, rather than an actual name
<project> is the project identifier rather than the actual repository name
I found that for some API endpoints, you can replace the whole project slug circleci/<organization_identifier>/<project_identifier> with the actual project ID (i.e, the one you find in the overview section of the project settings)
So for example:
https://circleci.com/api/v2/project/<project_ID>
and
https://circleci.com/api/v2/project/circleci/<organization_identifier>/<project_identifier>
will yield the same output.
Not knowing what your end goal is, I can't provide more specific suggestions. But if you explain in details what you're ultimately trying to achieve, I can try to help.
Edit:
I found out there is an undocumented endpoint you could use to retrieve the projects respective slugs: https://circleci.com/api/private/project?organization-id=your_org_id.
You can the use those project slugs with any project-related API endpoints.
I'm in trouble filtering projects by "tag" with the api (named topics in project settings).
I would get the same result as the following UI query https://gitlab.xxxxxx.com/explore/projects?tag=ruby
It returns all project that are tagged with the "ruby" topic.
Here is an example of result I have with the api when describing a single project:
curl --header "Authorization: Bearer $GITLAB_TOKEN" "https://gitlab.hostname.com/api/v4/projects/42?simple=true" | json_pp
...
"tag_list" : [
"ruby"
],
...
According to the documentation (https://docs.gitlab.com/ce/api/projects.html#list-all-projects) I should be able to filter on project tag_list using topic parameter
curl --header "Authorization: Bearer $GITLAB_TOKEN" "https://gitlab.hostname.com/api/v4/projects?topic=ruby&simple=true" | json_pp
But this query returns all my projects, even those without any tag or the wrong ones
I tried using "tag" or "tag_list" instead of "topic" but nothing worked as I expected
Is someone have an idea on how to proceed ?
Note that I'm using gitlab CE 13.9
As you mentioned, you're using gitlab version 13.9 and the ability of filtering projects by tag_list or topic has come with version 14 and later.
See:
https://docs.gitlab.com/13.11/ee/api/projects.html#list-all-projects
Another approach: using the new API topics.
See GitLab 14.5 (November 2021)
Manage project topics with the API
In this release, thanks to Jonas Wälter’s contributions, adding topics in project settings is easier than ever.
In addition to the latest project topic management features in the UI, you can now use the API to retrieve topics by list or ID.
We’ve also made it possible for administrators to create or edit topics through the API. This introduces full parity between project topic management in the UI and API.
See Documentation and Issue.
Listing projects assigned to a topic is still done through the project API, though.
But the API around topics is now more complete.
That API also includes, with GitLab 14.9 (March 2022):
API endpoint to delete project topics
In a previous release, we added the ability to create and manage project topics that are used to categorize projects and find similar new projects. However, we did not create a way to delete them.
In this release, thanks to Timo Furrer’s contribution, we added an API endpoint to delete project topics to make topic management more neat and efficient.
See Documentation and Issue.
I want to understand the difference between projects and subgroups in GitLab.
Please help me on understanding the above.
Project
A project manages one git repository and adds an issue tracker, a wiki, etc:
See: https://docs.gitlab.com/ee/user/project/index.html#doc-nav
Groups
Groups can be used to combine several projects under one topic. Examples:
You could put all your JavaScript projects in a group called "js"
You could create one group for each of your developer teams; then if somebody new joins a team, you can just add them to the group instead of having to grant developer access for every project.
Groups can be referred in issues or commit discussions.
See: https://docs.gitlab.com/ee/user/group/index.html#doc-nav
Different groups may have different permissions
Subgroups
Subgroups are only available in GitLab 9 and above; they allow you to create additional groups inside of groups, e.g. "js/frontend"; this is useful if you are working on a large project with several sub-projects. See the official documentation for some examples:
https://docs.gitlab.com/ee/user/group/subgroups/index.html
I want to automate our build so that we usually don't have to fiddle with our versions. Our versions follow the format:
${YY}.${Quarter}.${Sprint}.${patch}
Seems like I should be able to reach out to JIRA and grab that sprint number.
Jira has a REST API that also exposes board and sprint info.
Ie. GET /rest/agile/1.0/board/{boardId}/sprint
You can also add the state query parameter to only get the active sprint as mentioned in the docs.
It frequently happens that buildscripts also need info from commit messages or from jira issues for which code changes were made. All of these are accessible through apis like git cli, bitbucket/jira rest api, ...
I am currently using GitLab Community Edition 9.0.0 and want to change default branch to "develop" for every project.
I know it can be done by project settings page but since we have almost 200 projects, is there easy way to do it?
You could use the Gitlab API to:
Get a list of all the projects (see here)
Loop on that list and edit every project to set the default_branch parameter (see here)
Here's more documentation on how to use the API.
You fist need to get a user's private token. Go to http://<gitlab_domain>/profile/account to get/generate one for your currently logged in user. You may want to do that as the gitlab administrator in order to have access to and be able to modify all those projects.
Then you need to generate the proper requests (see links above and this).