jenkins pipeline 查询influxdb数据
2020-06-08 本文已影响0人
_fishman
原始influxdb数据
{
"results": [
{
"statement_id": 0,
"series": [
{
"name": "version",
"columns": [
"time",
"image_id"
],
"values": [
[
"2020-06-08T01:57:23.242796382Z",
"dev-xxx"
]
]
}
]
}
]
}
import java.net.URLEncoder
pipeline{
agent { node { label "master"}}
stages{
stage("Build"){
steps{
script{
def query = java.net.URLEncoder.encode('SELECT image_id FROM "version" WHERE "profile"=\'prd\' AND "product"=\'pay\' AND "srv_name"=\'demo\' order by time desc limit 1', "UTF-8")
apiUrl = "http://localhost:8086/query?db=mydb&pretty=true&q=${query}"
response = httpRequest contentType: 'APPLICATION_JSON' , url: "${apiUrl}"
def response = readJSON text: """${response.content}"""
image_id = response.results[0].series[0].values[0][-1]
println(image_id)
}
}
}
}
}