How do I retrieve a GitLab hosted Kubernetes Agent ClusterAgentID to delete the Agent?

The docs here: https://docs.gitlab.com/ee/user/clusters/agent/#remove-the-gitlab-kubernetes-agent

say to use the GraphQL endpoint do delete the agent and token. However, the GraphQL mutations require a ClusterAgentID: https://docs.gitlab.com/ee/api/graphql/reference/#mutationclusteragentdelete

mutation deleteAgent {
  clusterAgentDelete(input: { id: "<cluster-agent-id>" } ) {
    errors
  }
}

mutation deleteToken {
  clusterAgentTokenDelete(input: { id: "<cluster-agent-token-id>" }) {
    errors
  }
}

There is no corresponding mechanism to query for the ID nor is there a way to find it in the UI (and it does not appear to be part of the URL based on the documented format). The docs do not show where to retrieve the IDs from either.

Looking for a way to delete the Kubernetes agent in my GitLab project without having to delete the whole project.


Solution 1:

Found the answer:

{
  project(fullPath: "path/to/your/project") {
    clusterAgents {
      nodes {
        id
        name
      }
    }
  }
}

More properties here: https://docs.gitlab.com/ee/api/graphql/reference/#project