GitLabRestAPI

nicolaw 10th April 2018 at 2:06pm
CI/CD Git GitLab jq JSON TechnicalNotes
GITLAB_API_PRIVATE_TOKEN="Your_API_Token_Here"
GITLAB_API_ENDPOINT="https://gitlab-server.fqdn/api/v4"

curl () {
  command curl -sSL \
    --header "PRIVATE-TOKEN: ${GITLAB_API_PRIVATE_TOKEN}" \
    "$@"
}

curl "$GITLAB_API_ENDPOINT/groups" | jq .
curl "$GITLAB_API_ENDPOINT/groups/1234" | jq .
curl "$GITLAB_API_ENDPOINT/groups/1234/projects" | jq .
curl "$GITLAB_API_ENDPOINT/groups/1234/projects" | jq -r -c '.[].name'
# Change visibility of all projects in a group.
while read -r project_id
do
  curl -sSL --request PUT \
    --header "PRIVATE-TOKEN: ${GITLAB_API_PRIVATE_TOKEN}" \
    "${GITLAB_API_ENDPOINT}/projects/$project_id?visibility=internal" \
    | jq .
done < <(curl -sSL --request GET \
           --header "PRIVATE-TOKEN: ${GITLAB_API_PRIVATE_TOKEN}" \    
           "${GITLAB_API_ENDPOINT}/groups/3108/projects?per_page=500" \
           | jq '.[].id')