{
organization(slug: "xxxx") {
agents(first: 100) {
edges {
node {
name
jobs(first: 10, state: [FINISHED]) {
edges {
node {
... on JobTypeCommand {
build {
id
number
state
createdAt
finishedAt
pipeline {
name
}
}
}
}
}
}
}
}
}
}
}
I’m getting back a lot of jobs with the state RUNNING. Am I doing something wrong?
What I intend to get out of this query is a list of the latest jobs run by each agent, so that we know the health of that agent (i.e. did it fail the last jobs? does it fail often?)
That query doesn’t yield any results. All our agents are self-hosted, but we don’t have any cluster set up. They’re all unclustered. I’m wondering if that’s why we don’t get results back. I’ve tried the query without the clusterQueue param too, but got no results.
Also, I’m not looking for scheduled jobs like you did on your query, only for finished ones (failed, succeeded or canceled).
What is the issue with the query I posted in the first place? Why suggest something else? (serious question, I don’t have much experience with graphql, and want to understand)
Why your query doesn’t work:
If you go to the GraphQl documentation you will see agent(slug: ID!)
To get jobs running on a specific “each” agent, you have to specify the agent ID using the agent(slug: ID!) field in the GraphQL API. This means providing the full agent slug in the format your_org_slug/your_agent_id.
Regarding my query above, if you don’t use cluster, you can delete cluster from it. Something like that:
query getFinishedJobs{
organization(slug: "your_org_slug") {
jobs(
first: 500,
state: [FINISHED,CANCELED] #Put any state you want, from the list https://buildkite.com/docs/apis/graphql/schemas/enum/jobstates, in my example SCHEDULED was an example. =)
){
count
pageInfo{
endCursor
hasNextPage
}
edges{
node{
... on JobTypeCommand {
uuid
pipeline{
name
}
build{
number
}
url
state
}
}
}
}
}
}