Von der Community bereitgestellte und benutzerdefinierte Builder verwenden
Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Auf dieser Seite wird erläutert, wie Sie in Cloud Build Community-Community-Builder und benutzerdefinierte Builder verwenden. Die Entwickler-Community von Cloud Build bietet Open-Source-Builder, mit denen Sie Ihre Aufgaben ausführen können. Wenn die Aufgabe, die Sie ausführen möchten, Funktionen erfordert, die nicht von einem vorhandenen Image bereitgestellt werden, können Sie ein eigenes benutzerdefiniertes Image erstellen und in einem Build-Schritt verwenden. Weitere Informationen zu den verschiedenen Builder-Typen finden Sie unter Cloud Builder.
Vordefinierte Images sind für von der Community bereitgestellte Builder nicht verfügbar. Wenn Sie diese Builder in einer Cloud Build-Konfigurationsdatei verwenden möchten, müssen Sie zuerst das Image erstellen und in Artifact Registry in Ihrem Projekt hochladen.
So verwenden Sie einen von der Community bereitgestellten Builder:
Hier einige Beispiele, wann Sie ein benutzerdefiniertes Builder-Image verwenden können:
Herunterladen von Quellcode oder Paketen von externen Speicherorten
Verwenden einer externen Toolchain
Caching aller notwendigen Bibliotheken
Vorbereiten einer Quelle, wobei die einzige Aufgabe von Cloud Build darin besteht, den Build potenziell in ein Image zu verpacken.
Wie jeder andere Builder wird ein benutzerdefinierter Builder mit der unter /workspace bereitgestellten Quelle ausgeführt und mit einem Arbeitsverzeichnis in /workspace ausgeführt. Alle Dateien, die in einem bestimmten Build-Schritt in /workspace verbleiben, sind für andere Build-Schritte verfügbar.
Mit einem benutzerdefinierten Builder können Sie Push- oder Pull-Übertragungen zum bzw. vom Repository in der Artifact Registry durchführen, die unter gcr.io/$PROJECT-NAME/ gehostet wird, auf das Ihr Build-Dienstkonto Zugriff hat.
In den folgenden Schritten wird anhand eines Dockerfile-Beispiels gezeigt, wie Sie einen benutzerdefinierten Builder erstellen und verwenden:
Erstellen Sie ein benutzerdefiniertes Builder-Image:
Erstellen Sie Dockerfile für den benutzerdefinierten Builder. Der folgende Code zeigt ein Dockerfile-Beispiel:
FROMalpineRUNapkaddcurlCMDcurlhttps://httpbin.org/ip -s > myip.txt; echo "*** My IP is: $(cat myip.txt)"
Erstellen Sie den benutzerdefinierten Builder und übertragen Sie ihn in die Artifact Registry in Ihrem Projekt. Ersetzen Sie dabei die Werte für project-id und image-name:
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 2025-08-18 (UTC)."],[[["\u003cp\u003eCloud Build allows the use of community-contributed builders, which are open-source tools provided by the developer community, after building and pushing them to Container Registry.\u003c/p\u003e\n"],["\u003cp\u003eTo utilize a community-contributed builder, clone the \u003ccode\u003ecloud-builders-community\u003c/code\u003e repository, navigate to the desired builder's directory, submit it using \u003ccode\u003egcloud builds submit\u003c/code\u003e, and then reference it in your Cloud Build config file.\u003c/p\u003e\n"],["\u003cp\u003eCustom builders can be created and used when existing builders do not meet specific task requirements, such as downloading external code, using external toolchains, or pre-building source code.\u003c/p\u003e\n"],["\u003cp\u003eCreating a custom builder involves defining a \u003ccode\u003eDockerfile\u003c/code\u003e, building and pushing it to Container Registry, and then specifying the image in the \u003ccode\u003ename\u003c/code\u003e field of a Cloud Build step.\u003c/p\u003e\n"],["\u003cp\u003eContainer Registry, which is used to store the builders, is scheduled for shutdown on March 18, 2025 and organizations which have not used it prior to January 8, 2024 will have new repositories hosted on Artifact Registry by default.\u003c/p\u003e\n"]]],[],null,["# Using community-contributed builders and custom builders\n\nThis page explains how to use [community-contributed builders](https://github.com/GoogleCloudPlatform/cloud-builders-community) and custom builders in Cloud Build. The\nCloud Build developer community provides [open-source\nbuilders](https://github.com/GoogleCloudPlatform/cloud-builders-community)\nthat you can use to execute your tasks. If the task you want to perform requires\ncapabilities that are not provided by an existing image, you can build your own\ncustom image and use it in a build step. To learn about the different types of\nbuilders, see [Cloud Builders](/build/docs/cloud-builders).\n\nIf you're new to Cloud Build, read the [quickstarts](/build/docs/quickstarts)\nand the [Build configuration overview](/build/docs/build-config) first.\n\nUsing community-contributed builders\n------------------------------------\n\nPrebuilt images are not available for community-contributed builders; to use\nthese builders in a Cloud Build config file, you must first build the\nimage and push it to [Artifact Registry](/artifact-registry/docs/overview) in\nyour project.\n\nTo use a community-contributed builder:\n\n1. Build and push the builder:\n\n 1. Navigate to your project root directory.\n\n 2. Clone the [cloud-builders-community](https://github.com/GoogleCloudPlatform/cloud-builders-community) repository:\n\n git clone https://github.com/GoogleCloudPlatform/cloud-builders-community.git\n\n 3. Navigate to the builder image you want to use, where \u003cvar translate=\"no\"\u003ebuilder-name\u003c/var\u003e\n is the directory that contains the builder:\n\n cd cloud-builders-community/\u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003ebuilder\u003c/span\u003e\u003cspan class=\"devsite-syntax-o\"\u003e-\u003c/span\u003e\u003cspan class=\"devsite-syntax-n\"\u003ename\u003c/span\u003e\u003c/var\u003e\n\n 4. Submit the builder to your project:\n\n gcloud builds submit .\n\n 5. Navigate back to your project root directory:\n\n cd ../..\n\n 6. Remove the repository from your root directory:\n\n rm -rf cloud-builders-community/\n\n2. In your Cloud Build config file, use the builder in a build step:\n\n ### YAML\n\n steps:\n - name: 'gcr.io/\u003cvar translate=\"no\"\u003eproject-id\u003c/var\u003e/\u003cvar translate=\"no\"\u003ebuilder-name\u003c/var\u003e'\n args: ['\u003cvar translate=\"no\"\u003earg1\u003c/var\u003e', '\u003cvar translate=\"no\"\u003earg2\u003c/var\u003e', ...]\n ...\n\n ### JSON\n\n {\n \"steps\": [\n {\n \"name\": \"gcr.io/\u003cvar translate=\"no\"\u003eproject-id\u003c/var\u003e/\u003cvar translate=\"no\"\u003ebuilder-name\u003c/var\u003e\",\n \"args\": [\n \"\u003cvar translate=\"no\"\u003earg1\u003c/var\u003e\",\n \"\u003cvar translate=\"no\"\u003earg2\u003c/var\u003e\",\n ...\n ]\n ...\n }\n ]\n }\n\n3. Use the build config file to start the [build manually](/build/docs/running-builds/start-build-manually)\n or [build using triggers](/build/docs/automating-builds/create-manage-triggers).\n\nFor examples on using community-contributed builders, see\n[Deploy to Firebase](/build/docs/deploying-builds/deploy-firebase)\nand [Build VM images using Packer](/build/docs/building/build-vm-images-with-packer).\n\nCreating a custom builder\n-------------------------\n\nIf the task you want to perform requires capabilities that are not provided by\n[a public image, a supported builder, or a community-contributed builder](/build/docs/cloud-builders),\nyou can build your own image and use it in a build step.\n\nSome examples of when you might want to use a custom builder image are:\n\n- Downloading source code or packages from external locations.\n- Using an external tool chain.\n- Caching any necessary libraries.\n- Pre-building source (with Cloud Build responsible only for potentially packaging the build into an image).\n\nLike any other builder, a custom builder runs with the source mounted under\n`/workspace`, and is run with a working directory in `/workspace`. Any files left\nin `/workspace` by a given build step are available to other build steps.\n\nYour custom builder can push to or pull from a repository in\n[Artifact Registry](/artifact-registry/docs/overview) (hosted at `gcr.io/$PROJECT-NAME/`)\nto which your [build service account](/build/docs/securing-builds/configure-user-specified-service-accounts) has\naccess.\n\nThe following steps show how to create and use a custom builder with an example\n`Dockerfile`:\n\n1. Create a custom builder image:\n\n 1. Create the `Dockerfile` for the custom builder. The following\n code shows an example `Dockerfile`:\n\n FROM alpine\n RUN apk add curl\n CMD curl https://httpbin.org/ip -s \u003e myip.txt; echo \"*** My IP is: $(cat myip.txt)\"\n\n 2. Build and push the custom builder to the Artifact Registry in your project,\n replacing values for \u003cvar translate=\"no\"\u003eproject-id\u003c/var\u003e and \u003cvar translate=\"no\"\u003eimage-name\u003c/var\u003e:\n\n gcloud builds submit --tag gcr.io/\u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003eproject\u003c/span\u003e\u003cspan class=\"devsite-syntax-o\"\u003e-\u003c/span\u003e\u003cspan class=\"devsite-syntax-n\"\u003eid\u003c/span\u003e\u003c/var\u003e/\u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003eimage\u003c/span\u003e\u003cspan class=\"devsite-syntax-o\"\u003e-\u003c/span\u003e\u003cspan class=\"devsite-syntax-n\"\u003ename\u003c/span\u003e\u003c/var\u003e\n\n2. Use the custom builder image in Cloud Build by specifying the builder\n in the `name` field of a build step:\n\n ### YAML\n\n steps:\n - name: 'gcr.io/\u003cvar translate=\"no\"\u003eproject-id\u003c/var\u003e/\u003cvar translate=\"no\"\u003eimage-name\u003c/var\u003e'\n id: Determine IP of this build worker\n\n ### JSON\n\n {\n \"steps\": [\n {\n \"name\": \"gcr.io/\u003cvar translate=\"no\"\u003eproject-id\u003c/var\u003e/\u003cvar translate=\"no\"\u003eimage-name\u003c/var\u003e\",\n \"id\": \"Determine IP of this build worker\"\n }\n ]\n }\n\n3. Use the build config file to start the [build manually](/build/docs/running-builds/start-build-manually)\n or [build using triggers](/build/docs/automating-builds/create-manage-triggers).\n\n| **Note:** Users can specify a working directory using the `dir` field in a build config file. Because your custom builder's users may specify any `dir` value, the builder should avoid hard-coding `/workspace` if possible. Instead, use the current working directory and relative paths.\n\nWhat's next\n-----------\n\n- Learn how to [run bash scripts in build steps](/build/docs/configuring-builds/run-bash-scripts).\n- Learn how to [configure build step order](/build/docs/configuring-builds/configure-build-step-order).\n- Learn how to [write a basic build config file](/build/docs/configuring-builds/create-basic-configuration)."]]