Skip to content

Instantly share code, notes, and snippets.

@caioagiani
Created June 28, 2024 03:23
Show Gist options
  • Save caioagiani/d9ce65a51ed002ac3be316057b79e792 to your computer and use it in GitHub Desktop.
Save caioagiani/d9ce65a51ed002ac3be316057b79e792 to your computer and use it in GitHub Desktop.
#!/bin/bash
# chmod +x gitlab-environments.sh
# ./gitlab-environments.sh <ID>
if [ -z "$1" ]; then
echo "Uso: $0 <ID do Projeto>"
exit 1
fi
PROJECT_ID="$1"
GITLAB_URL="https://gitlab.link.com.br"
PRIVATE_TOKEN="your_private_token"
INTEGRATIONS_API_ENDPOINT="$GITLAB_URL/api/v4/projects/$PROJECT_ID/services"
VARIABLES_API_ENDPOINT="$GITLAB_URL/api/v4/projects/$PROJECT_ID/variables"
PIPELINES_API_ENDPOINT="$GITLAB_URL/api/v4/projects/$PROJECT_ID/pipelines"
RUNNERS_API_ENDPOINT="$GITLAB_URL/api/v4/projects/$PROJECT_ID/runners"
fetch() {
local url=$1
curl --silent --header "PRIVATE-TOKEN: $PRIVATE_TOKEN" "$url"
}
integrations_response=$(fetch "$INTEGRATIONS_API_ENDPOINT")
variables_response=$(fetch "$VARIABLES_API_ENDPOINT")
pipelines_response=$(fetch "$PIPELINES_API_ENDPOINT")
runners_response=$(fetch "$RUNNERS_API_ENDPOINT")
combined_response=$(cat <<EOF
{
"integrations": $integrations_response,
"variables": $variables_response,
"pipelines": $pipelines_response,
"runners": $runners_response
}
EOF
)
if [ $? -eq 0 ]; then
echo "$combined_response" | jq .
else
echo "Erro ao obter configurações de integração ou variáveis de ambiente"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment