Skip to content

Instantly share code, notes, and snippets.

@tom1299
Created October 21, 2022 10:12
Embed
What would you like to do?
A query for calculating the average running time of a job in a GitLab pipeline.
db.pipelines.aggregate([
{
$unwind: "$jobs"
},
{
$group: {
_id: {
"project": "$project_id",
"jobName": "$jobs.name"
},
averageRun: {
$avt: {
$dateDiff: {
startDate: {
"$dateFromString": {
"dateString": "$jobs.started_at",
"format": "%Y-%m-%dT%H:%M:%S.%LZ"
}
},
endDate: {
"$dateFromString": {
"dateString": "$jobs.finished_at",
"format": "%Y-%m-%dT%H:%M:%S.%LZ"
}
},
unit: "second"
}
}
}
}
}
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment