Implementación continua desde Git mediante Cloud Build
Organiza tus páginas con colecciones
Guarda y categoriza el contenido según tus preferencias.
Puedes usar Cloud Build para automatizar las implementaciones y compilaciones en Knative serving con el activador de Cloud Build para compilar e implementar tu código de forma automática cada vez que se envíen confirmaciones nuevas a una rama específica de un repositorio de Git.
Cuando usas un activador de Cloud Build para compilar contenedores, la información del repositorio de código fuente se muestra en la consola de Google Cloud para tu servicio después de la implementación en Knative serving.
Antes de comenzar
Tienes un repositorio de Git con un Dockerfile o tu base de código está escrita en uno de los lenguajes compatibles con los buildpacks de Google Cloud: Go, Node.js, Python, Java o .NET Core.
Enable the Cloud Build and Cloud Source Repositories
APIs.
Configura la implementación continua desde la interfaz de usuario de Knative serving
El procedimiento varía un poco en función de si configuras la implementación continua en un servicio nuevo o en uno existente. Haz clic en la pestaña correspondiente para obtener más información.
Servicio nuevo
Ve a Knative serving en la consola de Google Cloud:
Completa la Configuración del servicio (Service settings) con tus preferencias.
Haz clic en Siguiente.
Selecciona Continuously deploy new revisions from a source repository.
Haz clic en Configuración con Cloud Build (Set up with Cloud Build).
Selecciona el proveedor y el repositorio.
GitHub: Si aún no estás autenticado, haz clic en Autenticar y sigue las instrucciones. De forma predeterminada, la conexión de un repositorio se realiza a través de la app de GitHub de Cloud Build. Como alternativa, puedes duplicar el repositorio de GitHub en Cloud Source Repositories. Para hacerlo, haz clic en Opciones avanzadas (Advanced options) y marca Duplicar el repositorio de GitHub con Cloud Source Repositories. Más información
Bitbucket: Si aún no estás autenticado, haz clic en Autenticar y sigue las instrucciones.
Completa las opciones del paso Configuración de compilación (Build Configuration):
Rama (Branch): Indica qué fuente se debe usar cuando se ejecuta el activador. Puedes ingresar la regex aquí. Las ramas coincidentes se verifican de forma automática, y puedes verlas debajo de la entrada. Ten en cuenta que si solo coincide una rama, el activador se ejecutará de manera automática después de la creación.
Build Type
Si el repositorio se debe compilar con Docker y contiene un Dockerfile, selecciona Dockerfile. En Ubicación de origen (Source location), se indica la ubicación y el nombre del Dockerfile. El directorio se usará como el contexto de compilación de Docker. Todas las rutas de acceso deben estar relacionadas con el directorio actual.
De lo contrario, selecciona Google Cloud Buildpacks. Usa Buildpack context para especificar el directorio y Entrypoint (opcional) a fin de proporcionar el comando que inicia el servidor. Por ejemplo, gunicorn -p :8080 main:app para Python, java -jar target/myjar.jar para Java. Déjalo en blanco para usar el comportamiento predeterminado.
Haz clic en Guardar (Save).
Verifica la configuración seleccionada.
Haz clic en Crear (Create).
Ten en cuenta que se te redireccionará a la página Detalles del servicio, en la que podrás realizar un seguimiento del progreso de la configuración de la implementación continua.
Una vez que hayas completado todos los pasos, ten en cuenta las opciones adicionales:
Ubica el servicio en la lista de servicios y haz clic en él.
Haz clic en Configura la implementación continua.
Selecciona el proveedor y el repositorio.
GitHub: Si aún no estás autenticado, haz clic en Autenticar y sigue las instrucciones. De forma predeterminada, la conexión de un repositorio se realiza a través de la app de GitHub de Cloud Build. Como alternativa, puedes duplicar el repositorio de GitHub en Cloud Source Repositories. Para hacerlo, haz clic en Opciones avanzadas (Advanced options) y marca Duplicar el repositorio de GitHub con Cloud Source Repositories. Más información
Bitbucket: Si aún no estás autenticado, haz clic en Autenticar y sigue las instrucciones.
Completa las opciones del paso Configuración de compilación (Build Configuration):
Rama (Branch): Indica qué fuente se debe usar cuando se ejecuta el activador. Puedes ingresar la regex aquí. Las ramas coincidentes se verifican de forma automática, y puedes verlas debajo de la entrada. Ten en cuenta que si solo coincide una rama, el activador se ejecutará de manera automática después de la creación.
Build Type
Si el repositorio se debe compilar con Docker y contiene un Dockerfile, selecciona Dockerfile. En Ubicación de origen (Source location), se indica la ubicación y el nombre del Dockerfile. El directorio se usará como el contexto de compilación de Docker. Todas las rutas de acceso deben estar relacionadas con el directorio actual.
De lo contrario, selecciona Google Cloud Buildpacks. Usa Buildpack context para especificar el directorio y Entrypoint (opcional) a fin de proporcionar el comando que inicia el servidor. Por ejemplo, gunicorn -p :8080 main:app para Python, java -jar target/myjar.jar para Java. Déjalo en blanco para usar el comportamiento predeterminado.
Haz clic en Guardar (Save).
La página se vuelve a cargar y se muestra el progreso de la configuración de la implementación continua.
Una vez que hayas completado todos los pasos, ten en cuenta las opciones adicionales:
Adjunta el activador de Cloud Build existente al servicio de Knative serving.
Si ya tienes un activador de Cloud Build existente, puedes vincularlo al servicio y aprovechar las funciones de la consola de Google Cloud de la página Detalles del servicio: el botón Editar implementación continua y el gráfico Historial de compilaciones.
Para hacerlo, debes agregar una etiqueta con gcb-trigger-id como clave y el identificador único del activador de Cloud Build como valor (no el nombre del activador). Consulta estas instrucciones para configurar la etiqueta.
[[["Fácil de comprender","easyToUnderstand","thumb-up"],["Resolvió mi problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Información o código de muestra incorrectos","incorrectInformationOrSampleCode","thumb-down"],["Faltan la información o los ejemplos que necesito","missingTheInformationSamplesINeed","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Otro","otherDown","thumb-down"]],["Última actualización: 2025-05-06 (UTC)"],[],[],null,["# Continuous deployment from Git using Cloud Build\n\nYou can use Cloud Build to automate builds and deployments to\nKnative serving by using [Cloud Build trigger](/build/docs/running-builds/automate-builds)\nto automatically build and deploy your code whenever new commits are pushed to\na given branch of a Git repository.\n\nWhen you use a Cloud Build trigger to build containers, the\n[source repository information is displayed](/kubernetes-engine/enterprise/knative-serving/docs/managing/revisions#build-source)\nin the Google Cloud console for your service after you deploy to\nKnative serving.\n\nBefore you begin\n----------------\n\n- You either have a git repository with a `Dockerfile` or your codebase is written in one of the languages supported by [Google Cloud's buildpacks](/docs/buildpacks/overview): Go, Node.js, Python, Java or .NET Core.\n-\n\n\n Enable the Cloud Build and Cloud Source Repositories\n APIs.\n\n\n [Enable the APIs](https://console.cloud.google.com/flows/enableapi?apiid=sourcerepo.googleapis.com,cloudbuild.googleapis.com)\n\nSetting up continuous deployment from the Knative serving user interface\n------------------------------------------------------------------------\n\nThe procedure varies slightly depending on whether you are setting up\ncontinuous deployment on a new service or on an existing service. Click the\nappropriate tab to learn more. \n\n### New service\n\n1. Go to Knative serving in the Google Cloud console:\n\n [Go to Knative serving](https://console.cloud.google.com/kubernetes/run)\n2. Click **Create service**.\n\n3. Fill the *Service Settings* with your preferences.\n\n4. Click **Next**.\n\n5. Select **Continuously deploy new revisions from a source repository**.\n\n6. Click **Set up with Cloud Build**.\n\n7. Select the provider and the repository.\n\n - *GitHub* - if you are not yet authenticated, click **Authenticate** and follow the instructions. By default, connecting a repository is done via the Cloud Build GitHub app. Alternatively, you can mirror your GitHub repository in Cloud Source Repositories. To do so, click *Advanced option* and check *Mirror GitHub repository using\n Cloud Source Repositories* [Learn more](/build/docs/automating-builds/create-github-app-triggers?#different_types_of_github-based_triggers)\n - *Bitbucket* - if you are not yet authenticated, click **Authenticate** and follow the instructions.\n - [*Cloud Source Repositories*](/source-repositories/docs)\n\n8. Click **Next**.\n\n9. Fill the options in Build Configuration step:\n\n - *Branch* - indicates what source should be used when running the trigger. You can put the [regex](https://github.com/google/re2/wiki/Syntax) here. Matched branches are automatically verified: you can see them below the input. Note that if exactly one branch is matched, the trigger will be automatically executed after the creation.\n - *Build Type*\n\n - If your repository should be built using Docker and it contains a\n Dockerfile, select **Dockerfile** . **Source location** indicates the\n location and name of the Dockerfile. This directory will be used as the\n Docker build context. All paths should be relative to the current\n directory.\n\n - Otherwise, select **Google Cloud Buildpacks** . Use\n **Buildpack context** to specify the directory and **Entrypoint**\n (optional) to provide the command to start the server. Example:\n `gunicorn -p :8080 main:app` for Python,\n `java -jar target/myjar.jar` for Java. Leave it blank to use\n [default behavior](/docs/buildpacks/service-specific-configs).\n\n10. Click **Save**.\n\n11. Verify the selected settings.\n\n12. Click **Create**.\n\n13. Note that you are redirected to the *Service Details* page, where you can\n track the progress of your Continuous Deployment set up.\n\n14. Once all steps are completed, note additional options:\n\n - Edit Continuous Deployment button.\n - Build History.\n - Source details in the [*Revision Details* section](/kubernetes-engine/enterprise/knative-serving/docs/managing/revisions#viewing_revision_details).\n\n### Existing service\n\n1. Go to Knative serving in the Google Cloud console:\n\n [Go to Knative serving](https://console.cloud.google.com/kubernetes/run)\n2. Locate the service in the services list, and click on it.\n\n3. Click **Set up Continuous Deployment**.\n\n4. Select the provider and the repository.\n\n - *GitHub* - if you are not yet authenticated, click **Authenticate** and follow the instructions. By default, connecting a repository is done via the Cloud Build GitHub app. Alternatively, you can mirror your GitHub repository in Cloud Source Repositories. To do so, click *Advanced option* and check *Mirror GitHub repository using\n Cloud Source Repositories* [Learn more](/build/docs/automating-builds/create-github-app-triggers?#different_types_of_github-based_triggers)\n - *Bitbucket* - if you are not yet authenticated, click **Authenticate** and follow the instructions.\n - [*Cloud Source Repositories*](/source-repositories/docs)\n\n5. Click **Next**.\n\n6. Fill the options in Build Configuration step:\n\n - *Branch* - indicates what source should be used when running the trigger. You can put the [regex](https://github.com/google/re2/wiki/Syntax) here. Matched branches are automatically verified: you can see them below the input. Note that if exactly one branch is matched, the trigger will be automatically executed after the creation.\n - *Build Type*\n\n - If your repository should be built using Docker and it contains a\n Dockerfile, select **Dockerfile** . **Source location** indicates the\n location and name of the Dockerfile. This directory will be used as the\n Docker build context. All paths should be relative to the current\n directory.\n\n - Otherwise, select **Google Cloud Buildpacks** . Use\n **Buildpack context** to specify the directory and **Entrypoint**\n (optional) to provide the command to start the server. Example:\n `gunicorn -p :8080 main:app` for Python,\n `java -jar target/myjar.jar` for Java. Leave it blank to use\n [default behavior](/docs/buildpacks/service-specific-configs).\n\n7. Click **Save**.\n\n8. The page reloads and displays the progress of the\n Continuous Deployment setup.\n\n9. Once all steps are completed, note additional options:\n\n - Edit Continuous Deployment button.\n - Build History.\n - Source details in the [*Revision Details* section](/kubernetes-engine/enterprise/knative-serving/docs/managing/revisions#viewing_revision_details).\n\nSetting up continuous deployment manually\n-----------------------------------------\n\nRefer to\n[Setting up continuous deployment manually](/build/docs/deploying-builds/deploy-cloud-run)\nif you need to use a manual procedure and not the UI.\n\nAttach existing Cloud Build trigger to Knative serving service.\n---------------------------------------------------------------\n\nIf you already have an existing Cloud Build trigger, you can attach it to\nthe service and take advantage of Google Cloud console features in the Service\nDetails page: **Edit Continuous Deployment** button and **Build History** chart.\n\nTo do so, you have to add a label with \u003cvar translate=\"no\"\u003egcb-trigger-id\u003c/var\u003e as a key and\nthe unique identifier of the Cloud Build trigger as value (not the trigger\nname). See [instructions](/kubernetes-engine/enterprise/knative-serving/docs/configuring/labels#set-labels) for\nsetting up the label."]]