Table: jenkins_pipeline - Query Jenkins Pipelines using SQL
Jenkins is a self-contained, open-source automation server which can be used to automate all sorts of tasks related to building, testing, and delivering or deploying software. Jenkins Pipelines are a suite of plugins supporting implementation and integration of continuous delivery pipelines into Jenkins. It provides an extensible set of tools for modeling simple-to-complex delivery pipelines as code.
Table Usage Guide
The jenkins_pipeline
table provides insights into Jenkins Pipelines within the Jenkins automation server. As a DevOps engineer, explore pipeline-specific details through this table, including configurations, status, and associated metadata. Utilize it to uncover information about pipelines, such as their current status, the steps involved in the pipeline, and the verification of pipeline configurations.
Examples
Pipelines in queue
Discover the segments that are currently in queue within the Jenkins pipeline, providing you with a quick overview and access to their URLs. This is useful to prioritize tasks and manage workflow efficiently.
select full_display_name, urlfrom jenkins_pipelinewhere in_queue;
select full_display_name, urlfrom jenkins_pipelinewhere in_queue = 1;
Top bad health-scored pipelines
Uncover the details of your Jenkins pipelines with the lowest health scores to understand potential areas of improvement. This query is particularly useful in identifying pipelines that might require immediate attention due to their poor health scores.
select health_report -> 0 ->> 'score' as health_report_score, full_display_name, health_report -> 0 ->> 'description' as health_report_descriptionfrom jenkins_pipelineorder by health_report_score desc;
select json_extract(json_extract(health_report, '$[0]'), '$.score') as health_report_score, full_display_name, json_extract( json_extract(health_report, '$[0]'), '$.description' ) as health_report_descriptionfrom jenkins_pipelineorder by health_report_score desc;
Health color of a pipeline
Analyze the health status of a specific pipeline in a Jenkins project. This query is particularly useful for understanding the operational state of a pipeline, which can guide troubleshooting efforts or inform operational decisions.
select full_display_name as pipeline, color as health_colorfrom jenkins_pipelinewhere full_name = 'corp-project/build-and-test-pipeline';
select full_display_name as pipeline, color as health_colorfrom jenkins_pipelinewhere full_name = 'corp-project/build-and-test-pipeline';
How long a pipeline usually takes to run (in seconds)?
Analyze the average time it takes for a successful pipeline to run in your project, aiding in performance optimization and resource planning. This can help identify any potential bottlenecks and improve overall efficiency.
select ROUND(avg(b.duration) / 1000) as average_durationfrom jenkins_pipeline as p join jenkins_build as b on b.job_full_name = p.full_namewhere b.result = 'SUCCESS' and p.full_name = 'corp-project/build-and-test-pipeline'group by b.result;
select ROUND(avg(b.duration) / 1000) as average_durationfrom jenkins_pipeline as p join jenkins_build as b on b.job_full_name = p.full_namewhere b.result = 'SUCCESS' and p.full_name = 'corp-project/build-and-test-pipeline'group by b.result;
Pipeline's last successful build
Explore which Jenkins pipelines had successful builds last, providing a quick overview of successful deployments. This can help in assessing the stability and reliability of different pipelines.
select full_display_name, last_successful_build ->> 'URL' as last_successful_buildfrom jenkins_pipelineorder by full_display_name;
select full_display_name, json_extract(last_successful_build, '$.URL') as last_successful_buildfrom jenkins_pipelineorder by full_display_name;
Pipelines where the last build failed
This query helps identify pipelines where the most recent build was unsuccessful, providing insights into potential issues and facilitating quick troubleshooting. It's useful for maintaining the health and efficiency of your Jenkins pipelines.
select full_display_name as pipeline, color, health_report -> 0 ->> 'score' as health_report_score, health_report -> 0 ->> 'description' as health_report_description, last_unsuccessful_build ->> 'URL' as last_unsuccessful_buildfrom jenkins_pipelinewhere last_build ->> 'Number' != '0' and last_build ->> 'Number' = last_unsuccessful_build ->> 'Number'order by full_display_name;
select full_display_name as pipeline, color, json_extract(health_report, '$[0].score') as health_report_score, json_extract(health_report, '$[0].description') as health_report_description, json_extract(last_unsuccessful_build, '$.URL') as last_unsuccessful_buildfrom jenkins_pipelinewhere json_extract(last_build, '$.Number') != '0' and json_extract(last_build, '$.Number') = json_extract(last_unsuccessful_build, '$.Number')order by full_display_name;
Schema for jenkins_pipeline
Name | Type | Operators | Description |
---|---|---|---|
_ctx | jsonb | Steampipe context in JSON form, e.g. connection_name. | |
actions | jsonb | Data about the pipeline trigger. | |
buildable | boolean | Boolean to indicate whether the pipeline is able to run a build. | |
builds | jsonb | List of builds of the pipeline. | |
color | text | Color indicating the health of the pipeline based on the result of recent builds. | |
concurrent_build | boolean | Boolean to indicate whether the pipeline is able to run builds in parallel. | |
description | text | An optional description that can be added to the pipeline. | |
display_name | text | Human readable name of the pipeline. | |
first_build | jsonb | First build of the pipeline. | |
full_display_name | text | Human readable name of the pipeline, including folder. | |
full_name | text | = | Unique key for the pipeline. |
health_report | jsonb | Health data about recent builds. | |
in_queue | boolean | Boolean to indicate whether the pipeline is waiting on queue to run a build. | |
keep_dependencies | boolean | Boolean to indicate whether the pipeline will keep dependencies used on last build. | |
last_build | jsonb | Last build of the pipeline. | |
last_completed_build | jsonb | Last completed build of the pipeline. | |
last_failed_build | jsonb | Last failed build of the pipeline. | |
last_stable_build | jsonb | Last stable build of the pipeline. | |
last_successful_build | jsonb | Last successful build of the pipeline. | |
last_unstable_build | jsonb | Last unstable build of the pipeline. | |
last_unsuccessful_build | jsonb | Last unsuccessful build of the pipeline. | |
name | text | Name of the pipeline. | |
next_build_number | bigint | Number that will be assigned to build on next | |
property | jsonb | Properties of the pipeline. | |
title | text | The title of the resource. | |
url | text | Full URL to the pipeline. |
Export
This table is available as a standalone Exporter CLI. Steampipe exporters are stand-alone binaries that allow you to extract data using Steampipe plugins without a database.
You can download the tarball for your platform from the Releases page, but it is simplest to install them with the steampipe_export_installer.sh
script:
/bin/sh -c "$(curl -fsSL https://steampipe.io/install/export.sh)" -- jenkins
You can pass the configuration to the command with the --config
argument:
steampipe_export_jenkins --config '<your_config>' jenkins_pipeline