Compilare manualmente il codice nei repository di origine
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Questa pagina spiega come creare trigger manuali per compilare il codice
nei repository di origine. Gli attivatori manuali possono essere utilizzati
per richiamare le build manualmente, con la possibilità di sostituire i valori delle variabili di sostituzione definite al momento
della chiamata prima di eseguire una build. Puoi anche programmare trigger manuali
per l'esecuzione automatica a un orario specifico.
Per scoprire come avviare manualmente le build utilizzando gcloud CLI o l'API Cloud Build, consulta Avvio manuale delle build.
I trigger manuali ti consentono di configurare build che vengono eseguite solo
quando richiami il trigger sui repository connessi. Supponiamo che tu stia creando
una pipeline per il deployment del codice sorgente in un ambiente di gestione temporanea o di produzione.
Potresti voler automatizzare il flusso di lavoro, ma vuoi eseguire le build manualmente. A questo scopo, puoi definire trigger manuali.
I trigger manuali ti consentono di richiamare manualmente le build:
Recupero del codice sorgente da un repository ospitato con un ramo o un tag specificato.
Parametrizzare la build con sostituzioni che non devono essere passate
manualmente ogni volta che esegui una build.
Eseguire l'override dei valori delle variabili di sostituzione definite al momento dell'invocazione prima di
invocare una build.
Se vuoi eseguire le build dalla tua directory di lavoro locale anziché da un repository ospitato
o vuoi inviare le build senza creare un trigger, puoi eseguire il seguente
comando gcloud nella tua directory di lavoro:
Se selezioni globale come regione,
Cloud Build utilizza il pool predefinito
per eseguire la build.
Se selezioni una regione non globale e il
file di configurazione della build associato al trigger
specifica un pool privato, Cloud Build utilizza il pool privato
per eseguire la build. In questo caso, la regione specificata nel trigger deve corrispondere a quella in cui hai creato il pool privato.
Se selezioni una regione non globale e il file di configurazione della build associato al trigger non specifica un pool privato, Cloud Build utilizza il pool predefinito per eseguire la build nella stessa regione del trigger.
(Facoltativo) Descrizione: una descrizione del trigger.
Evento: seleziona Richiamo manuale per configurare il trigger in modo che le build vengano eseguite solo quando il trigger viene richiamato manualmente.
Origine: seleziona il repository da creare quando viene eseguito il trigger manuale. Puoi specificare 1ª generazione o 2ª generazione come origine.
Revisione: seleziona il ramo o il tag da creare quando viene eseguito l'attivatore manuale.
Ramo: imposta un trigger per la creazione su questo ramo.
Devi specificare un valore letterale. Le espressioni regolari non sono attualmente
supportate.
Tag: imposta un trigger da creare in questo tag. Devi specificare un valore
letterale. Le espressioni regolari non sono attualmente supportate.
Configurazione: seleziona il file di configurazione della build che si trova nel repository remoto o crea un file di configurazione della build incorporato da utilizzare per la build.
Tipo: seleziona il tipo di configurazione da utilizzare per la build.
File di configurazione di Cloud Build (yaml o json):
utilizza un file di configurazione della build per la configurazione.
Dockerfile: utilizza un Dockerfile per la configurazione.
Posizione: specifica la posizione per la configurazione.
Repository: se il file di configurazione si trova nel repository remoto, fornisci la posizione del file di configurazione della build, della directory Dockerfile o della directory dei buildpack. Se il tipo di configurazione della build
è Dockerfile o un buildpack, devi fornire
un nome per l'immagine risultante e, facoltativamente, un timeout per la
build. Dopo aver fornito il nome dell'immagine Dockerfile o del buildpack, vedrai un'anteprima del comando docker build o pack che verrà eseguito dalla build.
Inline: se hai selezionato
File di configurazione di Cloud Build (yaml o json) come opzione di configurazione, puoi specificare la configurazione della build inline. Fai clic su Apri editor per scrivere il file della configurazione di compilazione nella console Google Cloud utilizzando la sintassi YAML o JSON. Fai clic su Fine per salvare la configurazione della build.
Dopo aver fatto clic su Esegui attivatore, vedrai il riquadro della finestra Esegui attivatore
sul lato destro. Se hai specificato campi come un nome di ramo, un nome di tag o variabili di sostituzione, potrai ignorare questi campi al momento dell'invocazione.
Se hai specificato nuovi valori delle variabili per la sostituzione, fai clic su Esegui trigger
per eseguire la build.
Per eseguire trigger manuali in base a una pianificazione, consulta la sezione
Pianificazione delle build.
gcloud
Per eseguire un trigger manuale utilizzando lo strumento a riga di comando gcloud, esegui il seguente comando:
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-09-04 UTC."],[[["\u003cp\u003eManual triggers allow for the execution of builds on connected repositories only when the trigger is invoked, providing control over build timing.\u003c/p\u003e\n"],["\u003cp\u003eBuilds can be parameterized with substitution variables, which can be overridden at invocation time without requiring manual input each time.\u003c/p\u003e\n"],["\u003cp\u003eManual triggers can be created via the Google Cloud console or the \u003ccode\u003egcloud\u003c/code\u003e command-line tool, with options to specify source repository, branch, tag, and build configuration.\u003c/p\u003e\n"],["\u003cp\u003eRunning a manual trigger can be done through the console or the \u003ccode\u003egcloud\u003c/code\u003e command, and allows for overriding specified fields like branch names, tag names, or substitution variables.\u003c/p\u003e\n"],["\u003cp\u003eYou have the option to schedule manual triggers to run at a specific time, in addition to invoking them manually.\u003c/p\u003e\n"]]],[],null,["1st gen 2nd gen\n\nThis page explains how to create manual triggers to build code\nin source repositories. Manual triggers can be used\nto invoke builds manually, with the ability to override defined substitution variable values at\ninvocation time prior to running a build. You can also schedule manual\ntriggers to automatically run at a specific time.\n\nTo learn how to start builds manually using the gcloud CLI or\nthe Cloud Build API, see\n[Starting builds manually](/build/docs/running-builds/start-build-manually).\n\nBefore you begin\n\n-\n\n\n Enable the Cloud Build API.\n\n\n [Enable the API](https://console.cloud.google.com/flows/enableapi?apiid=cloudbuild.googleapis.com&redirect=https://cloud.google.com/build/docs/automating-builds/create-manual-triggers)\n\n\u003c!-- --\u003e\n\n- Have your source code ready.\n\nManual triggers\n\nManual triggers enable you to set up builds that are only executed\nwhen you invoke your trigger on connected repositories. Let's say you're creating\na pipeline for deploying your source code to a staging or production environment.\nYou might want to automate your workflow, but are only looking to execute builds\nmanually. You can define manual triggers to do so.\n\nManual triggers enable you to manually invoke builds by:\n\n- Fetching source code from a hosted repository with a specified branch or tag.\n- Parametizing your build with substitutions that don't need to be passed in manually each time you execute a build.\n- Overriding defined substitution variable values at invocation time prior to invoking a build.\n\nIf you want to execute builds from your local working directory instead of a hosted repository\nor want to submit builds without creating a trigger, you can run the following\n`gcloud` command in your working directory: \n\n gcloud builds submit --config \u003cvar translate=\"no\"\u003eBUILD_CONFIG\u003c/var\u003e \u003cvar translate=\"no\"\u003eSOURCE_CODE\u003c/var\u003e\n\nWhere:\n\n- \u003cvar translate=\"no\"\u003eBUILD_CONFIG\u003c/var\u003e is the path to the build config file.\n- \u003cvar translate=\"no\"\u003eSOURCE_CODE\u003c/var\u003e is the path or URL source code.\n\nTo learn more about how to use the `gcloud` command to start builds manually\nin your local directory, see [Starting builds manually](/build/docs/running-builds/start-build-manually).\n\nCreating manual triggers \n\nConsole\n\nTo create a manual trigger:\n\n1. Open the **Triggers** page:\n\n [Open the Triggers page](https://console.cloud.google.com/cloud-build/triggers)\n2. Select your project from the top of the page and click **Open**.\n\n3. Click **Create trigger**.\n\n4. Enter the following trigger settings:\n\n - **Name**: A name for your trigger.\n - **Region** : Select the [region](/build/docs/locations) for your trigger.\n\n - If you select **global** as the region, Cloud Build uses the default pool to run your build.\n - If you select a non-global region and the build config file associated with the trigger specifies a [private pool](/build/docs/private-pools/private-pools-overview), Cloud Build uses the private pool to run your build. In this case, the region you specify in your trigger must match the region where you created your private pool.\n - If you select a non-global region and the build config file associated with the trigger does **not** specify a private pool, Cloud Build uses the default pool to run your build in the same region as your trigger.\n - **Description** (Optional): A description for your trigger.\n\n - **Event** : Select **Manual invocation** to set up your trigger so that builds\n only run when the trigger is manually invoked.\n\n - **Source** : Select the repository to build when the manual trigger runs. You can\n specify **1st generation** or **2nd generation** as your source.\n\n | **Note:** The region of your repository must match the region of your trigger. If your source is in Cloud Source Repositories, your repository is not connected to a particular region, but to your project.\n | **Caution:** Effective June 17, 2024, Cloud Source Repositories isn't available\n | to new customers. If your organization hasn't\n | previously used Cloud Source Repositories, you can't enable the API or use\n | Cloud Source Repositories. New projects not connected to an organization can't enable the\n | Cloud Source Repositories API. Organizations that have used Cloud Source Repositories prior to\n | June 17, 2024 are not affected by this change.\n - **Revision**: Select the branch or tag to build when the manual trigger\n runs.\n\n - **Branch**: Set a trigger to build on this branch.\n You must specify a literal value. Regular expressions are not currently\n supported.\n\n - **Tag**: Set a trigger to build on this tag. You must specify a literal\n value. Regular expressions are not currently supported.\n\n - **Configuration**: Select the build config file located in\n your remote repository or create an inline build config file to\n use for your build.\n\n - **Type** : Select the type of configuration to use for your build.\n - **Cloud Build configuration file (yaml or json)**: Use a build config file for your configuration.\n - **Dockerfile** : Use a `Dockerfile` for your configuration.\n - **Location**: Specify the location for your configuration.\n\n - **Repository** : If your config file is located in your remote repository, provide the location of your [build config file](/build/docs/build-config), the `Dockerfile` directory, or the buildpacks directory. If your build config type is a `Dockerfile` or a buildpack, you will need to provide a name for the resulting image and optionally, a timeout for your build. When you've provided the `Dockerfile` or buildpack image name, you'll see a preview of the `docker build` or `pack` command that your build will execute.\n - **Inline** : If you selected **Cloud Build configuration file (yaml or json)** as your configuration option, you can specify your build config inline. Click **Open Editor** to write your build config file in the Google Cloud console using YAML or JSON syntax. Click **Done** to save your build config.\n\n | **Note:** Inline build configuration support is not available for `Dockerfile`.\n5. Click **Create** to create your manual trigger.\n\ngcloud\n\nFor a complete list of flags, see the [`gcloud` reference for how to create manual triggers](/../sdk/gcloud/reference/alpha/builds/triggers/create/manual).\n\nRunning manual triggers \n\nConsole\n\nTo run a manual trigger using Google Cloud console:\n\n1. Open the **Triggers** page in the Google Cloud console.\n\n [Open the triggers page](https://console.cloud.google.com/cloud-build/triggers)\n2. Locate your trigger in the list.\n\n3. Click **Run trigger**.\n\n After clicking **Run trigger** , you will see the **Run trigger** window pane\n on the right side. If you specified fields such as a branch name, tag\n name, or substitution variables, you will be able to override these fields\n at invocation time.\n | **Note:** You cannot specify any new fields or variables in this window pane. To do so, see instructions in the `gcloud` tab in this section.\n\n If you specified new variable values for your substitution, click **Run trigger**\n to execute your build.\n\n To run manual triggers on schedule, see\n [Scheduling builds](/build/docs/schedule-builds).\n\ngcloud\n\nTo run a manual trigger using the `gcloud` command-line tool, run the following\ncommand: \n\n gcloud builds triggers run \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003eTRIGGER_NAME\u003c/span\u003e\u003c/var\u003e \\\n --region=\u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003eREGION\u003c/span\u003e\u003c/var\u003e \\\n --branch=\u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003eBRANCH_NAME\u003c/span\u003e\u003c/var\u003e \\\n --substitutions=\u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003eSUBSTITUTION_VAR\u003c/span\u003e\u003c/var\u003e=\u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003eSUBSTITUTION_VALUE\u003c/span\u003e\u003c/var\u003e\n\nWhere:\n\n- \u003cvar translate=\"no\"\u003eTRIGGER_NAME\u003c/var\u003e is the name of your trigger.\n- \u003cvar translate=\"no\"\u003eREGION\u003c/var\u003e is the [region](/build/docs/locations) for your trigger.\n- \u003cvar translate=\"no\"\u003eBRANCH_NAME\u003c/var\u003e is the name of your branch. You can also specify a tag using `--tag` or a commit ID using `--sha`.\n- \\[Optional\\]\u003cvar translate=\"no\"\u003eSUBSTITUTION_VAR\u003c/var\u003e is the variable name for your substitution value.\n- \\[Optional\\] \u003cvar translate=\"no\"\u003eSUBSTITUTION_VALUE\u003c/var\u003e is the value associated with your substitution variable.\n\nTo run manual triggers on schedule, see [Scheduling builds](/build/docs/schedule-builds).\n\nNext steps\n\n- Learn how to [start builds manually](/build/docs/running-builds/start-build-manually) using `gcloud` commands or the Cloud Build API.\n- Learn how to [schedule builds](/build/docs/automating-builds/schedule-builds).\n- Learn how to [create and manage triggers](/build/docs/automating-builds/create-manage-triggers).\n- Learn how to [view build results](/build/docs/view-build-results).\n- Learn how to [troubleshoot build errors](/build/docs/troubleshooting)."]]