Hi I am currently using the Jenkins Exporter for Prometheus. What I’m trying to do is write a query that only shows me the most recent build number (largest number) from the label: number
of a given job from the below metric.
default_jenkins_builds_build_result_ordinal
My query has looked similar to this:
default_jenkins_builds_build_result_ordinal{jenkins_prod_job=“examplejob”,status=“SUCCESS”,number=~".*"} I’ve tried writing this query with max
and topk
with no success. This metric I’m querying publishes something like the last several failed and successful times this job has ran for the given example job. My end goal is to have the query that only shows me the most recent build number for any given job I’m querying and not the last 10-15 successful build numbers. Any help on figuring this out would be much appreciated thanks in advance.
Did you find how to solve this?
I’m in the same boat.
so i did find answer for the same what we have to do is
- go to your jenkins manage–>configsystem–>prometheus section—>check the collect metrics for each build run
- let jenkins run for a day
- go to grafana add panel stats and this is the query topk(1, max by (number) (default_jenkins_builds_build_result{job=“$jnk”, jenkins_job=~“$job_name”}))
- in above query jnk varibales is my jenkins server variable and job name is jenkins job name
- below is my json for panel
{
“datasource”: {
“uid”: “c9ef27eb-e2df-49b2-9467-f6d148a1be80”,
“type”: “prometheus”
},
“fieldConfig”: {
“defaults”: {
“unitScale”: true,
“mappings”: ,
“thresholds”: {
“mode”: “absolute”,
“steps”: [
{
“color”: “green”,
“value”: null
},
{
“color”: “red”,
“value”: 80
}
]
},
“color”: {
“mode”: “thresholds”
}
},
“overrides”:
},
“gridPos”: {
“h”: 4,
“w”: 7,
“x”: 0,
“y”: 0
},
“id”: 17,
“options”: {
“reduceOptions”: {
“values”: false,
“calcs”: [
“lastNotNull”
],
“fields”: “”,
“limit”: 1
},
“orientation”: “horizontal”,
“textMode”: “name”,
“wideLayout”: true,
“colorMode”: “background”,
“graphMode”: “area”,
“justifyMode”: “auto”,
“showPercentChange”: false
},
“pluginVersion”: “10.3.1”,
“targets”: [
{
“datasource”: {
“type”: “prometheus”,
“uid”: “c9ef27eb-e2df-49b2-9467-f6d148a1be80”
},
“editorMode”: “code”,
“expr”: “topk(1, max by (number) (default_jenkins_builds_build_result{job="$jnk", jenkins_job=~"$job_name"}))\r\n”,
“instant”: false,
“legendFormat”: “__auto”,
“range”: true,
“refId”: “A”
}
],
“title”: “Last build number”,
“transformations”: ,
“type”: “stat”
}
let me know if i answered this