Eine Build-Konfigurationsdatei enthält eine Anleitung, die Cloud Build zur Ausführung von Aufgaben gemäß Ihren Spezifikationen verwendet. Zum Beispiel kann Ihre Build-Konfigurationsdatei Anweisungen zum Erstellen, Packen und Hochladen von Docker-Images enthalten.
Auf dieser Seite wird das Schema der Cloud Build-Konfigurationsdatei erläutert. Anleitungen zum Erstellen und Verwenden einer Build-Konfigurationsdatei finden Sie unter Einfache Build-Konfigurationsdatei erstellen.
Struktur einer Build-Konfigurationsdatei
Build-Konfigurationsdateien werden mit der Ressource Build der Cloud Build API modelliert.
Sie können die Build-Konfigurationsdatei mit der YAML- oder der JSON-Syntax schreiben. Verwenden Sie die JSON-Syntax, wenn Sie Build-Anfragen mithilfe von HTTP-Tools eines Drittanbieters wie "curl" senden.
Eine Build-Konfigurationsdatei hat folgende Struktur:
YAML
steps:
- name: string
args: [string, string, ...]
env: [string, string, ...]
allowFailure: boolean
allowExitCodes: [string (int64 format), string (int64 format), ...]
dir: string
id: string
waitFor: [string, string, ...]
entrypoint: string
secretEnv: string
volumes: object(Volume)
timeout: string (Duration format)
script: string
automapSubstitutions: boolean
results: object(Results)
- name: string
...
- name: string
...
timeout: string (Duration format)
queueTtl: string (Duration format)
logsBucket: string
options:
env: [string, string, ...]
secretEnv: string
volumes: object(Volume)
sourceProvenanceHash: enum(HashType)
machineType: enum(MachineType)
diskSizeGb: string (int64 format)
substitutionOption: enum(SubstitutionOption)
dynamicSubstitutions: boolean
automapSubstitutions: boolean
logStreamingOption: enum(LogStreamingOption)
logging: enum(LoggingMode)
defaultLogsBucketBehavior: enum(DefaultLogsBucketBehavior)
pool: object(PoolOption)
pubsubTopic: string
requestedVerifyOption: enum(RequestedVerifyOption)
substitutions: map (key: string, value: string)
tags: [string, string, ...]
serviceAccount: string
secrets: object(Secret)
availableSecrets: object(Secrets)
artifacts: object(Artifacts)
goModules: [object(GoModules), ...]
mavenArtifacts: [object(MavenArtifact), ...]
pythonPackages: [object(PythonPackage), ...]
npmPackages: [object(npmPackage), ...]
images:
- [string, string, ...]
JSON
{
"steps": [
{
"name": "string",
"args": [
"string",
"string",
"..."
],
"env": [
"string",
"string",
"..."
],
"allowFailure": "boolean",
"allowExitCodes: [
"string (int64 format)",
"string (int64 format)",
"..."
],
"dir": "string",
"id": "string",
"waitFor": [
"string",
"string",
"..."
],
"entrypoint": "string",
"secretEnv": "string",
"volumes": "object(Volume)",
"timeout": "string (Duration format)",
"script" : "string",
"automapSubstitutions" : "boolean",
"results": "object(Results)"
},
{
"name": "string"
...
},
{
"name": "string"
...
}
],
"timeout": "string (Duration format)",
"queueTtl": "string (Duration format)",
"logsBucket": "string",
"options": {
"sourceProvenanceHash": "enum(HashType)",
"machineType": "enum(MachineType)",
"diskSizeGb": "string (int64 format)",
"substitutionOption": "enum(SubstitutionOption)",
"dynamicSubstitutions": "boolean",
"automapSubstitutions": "boolean",
"logStreamingOption": "enum(LogStreamingOption)",
"logging": "enum(LoggingMode)"
"defaultLogsBucketBehavior": "enum(DefaultLogsBucketBehavior)"
"env": [
"string",
"string",
"..."
],
"secretEnv": "string",
"volumes": "object(Volume)",
"pool": "object(PoolOption)"
"requestedVerifyOption": "enum(RequestedVerifyOption)"
},
"substitutions": "map (key: string, value: string)",
"tags": [
"string",
"string",
"..."
],
"serviceAccount": "string",
"secrets": "object(Secret)",
"availableSecrets": "object(Secrets)",
"artifacts": "object(Artifacts)",
"goModules": [object(GoModules), ...],
"mavenArtifacts": ["object(MavenArtifact)", ...],
"pythonPackages": ["object(PythonPackage)", ...],
"npmPackages": ["object(npmPackage)", ...],
"images": [
"string",
"string",
"..."
]
}
Jeder Abschnitt der Build-Konfigurationsdatei definiert einen Teil der Aufgabe, die Cloud Build ausführen soll:
Build-Schritte
Ein Build-Schritt gibt eine Aktion an, die Cloud Build ausführen soll. Cloud Build führt für jeden Build-Schritt einen Docker-Container als Instanz von docker runaus. Build-Schritte sind mit Befehlen in einem Skript vergleichbar und ermöglichen die flexible Ausführung beliebiger Anweisungen in einem Build. Wenn Sie ein Build-Tool in einen Container packen, kann Cloud Build dieses Tool als Teil des Builds ausführen. Standardmäßig führt Cloud Build alle Schritte eines Builds seriell auf demselben Computer aus.
Wenn Sie Schritte haben, die gleichzeitig ausgeführt werden können, verwenden Sie die Option waitFor.
Sie können in die Konfigurationsdatei bis zu 300 Build-Schritte aufnehmen.
Verwenden Sie das Feld steps in der Build-Konfigurationsdatei, um einen Build-Schritt anzugeben. Nachfolgend sehen Sie ein Snippet für die Art der Konfigurationsanweisung, die Sie im Feld steps angeben können:
YAML
steps:
- name: 'gcr.io/cloud-builders/kubectl'
args: ['set', 'image', 'deployment/mydepl', 'my-image=gcr.io/my-project/myimage']
env:
- 'CLOUDSDK_COMPUTE_ZONE=us-east4-b'
- 'CLOUDSDK_CONTAINER_CLUSTER=my-cluster'
- name: 'gcr.io/cloud-builders/docker'
args: ['build', '-t', 'gcr.io/my-project-id/myimage', '.']
JSON
{
"steps": [
{
"name": "gcr.io/cloud-builders/kubectl",
"args": [
"set",
"image"
"deployment/mydepl"
"my-image=gcr.io/my-project/myimage"
],
"env": [
"CLOUDSDK_COMPUTE_ZONE=us-east4-b",
"CLOUDSDK_CONTAINER_CLUSTER=my-cluster"