-
Notifications
You must be signed in to change notification settings - Fork 20
/
pipeline_preview.rs
69 lines (57 loc) · 2.25 KB
/
pipeline_preview.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
// pipeline_preview.rs
// Pipeline preview example.
use anyhow::Result;
use azure_devops_rust_api::pipelines;
use azure_devops_rust_api::pipelines::models::{Pipeline, RunPipelineParameters};
use std::env;
mod utils;
#[tokio::main]
async fn main() -> Result<()> {
// Get authentication credential
let credential = utils::get_credential()?;
// Get ADO configuration via environment variables
let organization = env::var("ADO_ORGANIZATION").expect("Must define ADO_ORGANIZATION");
let project = env::var("ADO_PROJECT").expect("Must define ADO_PROJECT");
let pipeline_name = env::args().nth(1).expect("Usage: pipeline_preview <name>");
// Create a pipelines client
let pipelines_client = pipelines::ClientBuilder::new(credential).build();
// List all pipelines in the specified organization/project
let pipelines = pipelines_client
.pipelines_client()
.list(&organization, &project)
.await?
.value;
println!("Total pipelines: {}", pipelines.len());
// Filter the pipelines to just those that contain the specified name
println!("\nMatched pipelines:");
let matched_pipelines: Vec<Pipeline> = pipelines
.iter()
.filter(|pipeline| pipeline.name.contains(&pipeline_name))
.cloned()
.collect();
if let Some(pipeline) = matched_pipelines.first() {
// Demonstrate how to query a preview of pipeline YAML...
// Define the pipeline params
let run_pipeline_params = RunPipelineParameters {
preview_run: Some(true),
resources: None,
stages_to_skip: vec![],
template_parameters: None,
variables: None,
yaml_override: None,
};
// Create a preview client
let preview_client = pipelines_client.preview_client();
// Request a preview of the specified pipeline
let preview = preview_client
.preview(&organization, run_pipeline_params, &project, pipeline.id)
.await?;
// Display the full pipeline YAML
if let Some(final_yaml) = preview.final_yaml {
println!("Pipeline preview:\n{}", final_yaml);
}
}
Ok(())
}