Update pipeline (v1)

Update the display name of an existing Eventarc pipeline.

Code sample

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;
import com.google.protobuf.FieldMask;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

public class UpdatePipeline {

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

  public static void updatePipeline(String projectId, String locationId, String pipelineId) throws Exception {
    try (EventarcClient client = EventarcClient.create()) {
      Pipeline pipeline =
          Pipeline.newBuilder()
              .setName(PipelineName.of(projectId, locationId, pipelineId).toString())
              .setDisplayName("Updated Pipeline Display Name")
              .build();
      FieldMask updateMask = FieldMask.newBuilder().addPaths("display_name").build();

      // Initiate the update operation and wait for completion
      Pipeline response = client.updatePipelineAsync(pipeline, updateMask).get(5, TimeUnit.MINUTES);
      System.out.println("Updated pipeline: " + response.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 updatePipeline method
 *
 * @param {string} projectId - The Google Cloud project ID where the pipeline is deployed.
 * @param {string} locationId - The Google Cloud region where the pipeline is deployed.
 * @param {string} pipelineId - The user-provided ID or name of the existing Pipeline to update.
 */
async function updatePipeline(projectId, locationId, pipelineId) {
  try {
    const pipeline = {
      name: `projects/${projectId}/locations/${locationId}/pipelines/${pipelineId}`,
      displayName: 'Updated Pipeline Display Name',
    };
    const updateMask = {
      paths: ['display_name'],
    };

    const [operation] = await client.updatePipeline({
      pipeline,
      updateMask,
    });

    // Wait for the long-running operation to complete.
    const [response] = await operation.promise();
    console.log(`Updated pipeline: ${response.name}`);
    return response;
  } catch (err) {
    if (err.code === status.NOT_FOUND) {
      console.error(`Pipeline not found: ${err.message}`);
    } else if (err.code === status.INVALID_ARGUMENT) {
      console.error(`Invalid argument: ${err.message}`);
    } else {
      console.error(`API operation failed with code ${err.code}: ${err.message}`);
    }
    throw err;
  }
}

module.exports = { updatePipeline };

What's next

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