Get pipeline (v1)

Get an existing Eventarc pipeline.

Code sample

Go

To authenticate to Eventarc, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.


import (
	"context"
	"fmt"
	"io"

	eventarc "cloud.google.com/go/eventarc/apiv1"
	eventarcpb "cloud.google.com/go/eventarc/apiv1/eventarcpb"
)

// getPipeline retrieves an existing Eventarc pipeline.
func getPipeline(ctx context.Context, w io.Writer, projectID string, locationID string, pipelineID string) error {
	name := fmt.Sprintf("projects/%s/locations/%s/pipelines/%s", projectID, locationID, pipelineID)

	client, err := eventarc.NewClient(ctx)
	if err != nil {
		return fmt.Errorf("eventarc.NewClient: %w", err)
	}
	defer client.Close()

	req := &eventarcpb.GetPipelineRequest{
		Name: name,
	}

	pipeline, err := client.GetPipeline(ctx, req)
	if err != nil {
		return fmt.Errorf("client.GetPipeline: %w", err)
	}

	fmt.Fprintf(w, "Retrieved pipeline: %s\n", pipeline.GetName())
	return nil
}

Java

To authenticate to Eventarc, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

import com.google.cloud.eventarc.v1.EventarcClient;
import com.google.cloud.eventarc.v1.Pipeline;
import com.google.cloud.eventarc.v1.PipelineName;

public class GetPipeline {

  public static void main(String[] args) throws Exception {
    String projectId = "example-project_id";
    String locationId = "example-location_id";
    String pipelineId = "example-pipeline_id";
    getPipeline(projectId, locationId, pipelineId);
  }

  public static void getPipeline(String projectId, String locationId, String pipelineId)
      throws Exception {
    try (EventarcClient client = EventarcClient.create()) {
      String name = PipelineName.of(projectId, locationId, pipelineId).toString();
      Pipeline pipeline = client.getPipeline(name);

      System.out.println("Pipeline retrieved: " + pipeline.getName());
    }
  }
}

Node.js

To authenticate to Eventarc, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

'use strict';

const {EventarcClient} = require('@google-cloud/eventarc');
const {status} = require('@grpc/grpc-js');

const client = new EventarcClient();

/**
 * Use the getPipeline method
 *
 * @param {string} projectId - The Google Cloud project ID.
 * @param {string} locationId - The Google Cloud region or location for the pipeline (for example, 'us-central1').
 * @param {string} pipelineId - The ID of the Eventarc pipeline to retrieve. Must match ^[a-z]([a-z0-9-]{0,61}[a-z0-9])?$.
 */
async function getPipeline(projectId, locationId, pipelineId) {
  try {
    const name = client.pipelinePath(projectId, locationId, pipelineId);

    const [pipeline] = await client.getPipeline({name});

    console.log(`Pipeline name: ${pipeline.name}`);
    console.log(`Pipeline state: ${pipeline.state || 'STATE_UNSPECIFIED'}`);
    return pipeline;
  } catch (err) {
    if (err.code === status.NOT_FOUND) {
      console.error(`Pipeline not found at ${projectId}/${locationId}/${pipelineId}`);
    } else if (err.code === status.PERMISSION_DENIED) {
      console.error(`Permission denied when retrieving pipeline ${pipelineId}`);
    } else {
      console.error(`API error retrieving pipeline: ${err.message}`);
    }
  }
}

module.exports = { getPipeline };

Python

To authenticate to Eventarc, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

import google.api_core.exceptions
from google.cloud import eventarc_v1

client = eventarc_v1.EventarcClient()


def get_pipeline(project_id: str, location_id: str, pipeline_id: str) -> None:
    """Retrieves an Eventarc pipeline.

    Args:
        project_id: The Google Cloud project ID.
        location_id: The Google Cloud location or region of the pipeline.
        pipeline_id: The caller-chosen identifier of the pipeline.
    """
    name = f"projects/{project_id}/locations/{location_id}/pipelines/{pipeline_id}"

    try:
        response = client.get_pipeline(name=name)
        print(f"Retrieved pipeline: {response.name}")
    except google.api_core.exceptions.NotFound:
        print(f"Pipeline not found: {name}")
    except google.api_core.exceptions.GoogleAPICallError as exc:
        print(f"API call failed: {exc}")

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.