Dieser Inhalt ist in der von Ihnen ausgewählten Sprache nicht verfügbar.
Chapter 3. Configuring build runs
As a platform engineer, you can configure build runs by defining the build reference, parameters, service account, output settings, retention rules, and volumes in a BuildRun custom resource (CR). You can use a BuildRun CR to manage how individual builds execute within a namespace on the cluster.
3.1. Configurable fields in build run Link kopierenLink in die Zwischenablage kopiert!
Configure a BuildRun custom resource (CR) by specifying input parameters, service account, outputs, and lifecycle settings.
The following table describes the required fields in your BuildRun custom resource (CR):
| Field | Description |
|---|---|
|
|
Specifies the API version of the resource. For example, |
|
|
Specifies the type of the resource. For example, |
|
|
Indicates the metadata that identifies the custom resource definition instance. For example, the name of the |
The following table describes optional fields in your BuildRun custom resource (CR):
| Field | Description |
|---|---|
|
|
Specifies an existing |
|
|
Specifies an embedded |
|
| Indicates the service account to use when building the image. |
|
|
Defines a custom timeout. This field value overwrites the value of the |
|
|
Indicates a name-value list to specify values for parameters defined in the build strategy. The parameter value overwrites the value of the parameter that is defined with the same name in your |
|
|
Indicates a custom location where the generated image will be pushed. This field value overwrites the value of the |
|
|
Indicates an existing secret to get access to the container registry. This secret will be added to the service account along with other secrets requested by the |
|
|
Defines additional environment variables that you can pass to the build container. This field value overrides any environment variables that are specified in the |
|
| Specifies which nodes Builds should run on. |
|
| Specifies the tolerations for the Builds pod. |
|
| Specifies the scheduler for the Builds pod |
You cannot use the spec.build.name and spec.build.spec fields together in the same CR because they are mutually exclusive.
3.2. Build reference definition Link kopierenLink in die Zwischenablage kopiert!
Configure the spec.build.name field in your BuildRun resource to reference a Build resource that indicates an image to build. The following example shows a BuildRun custom resource (CR) that configures the spec.build.name field:
3.3. Build specification definition Link kopierenLink in die Zwischenablage kopiert!
Define a complete build specification into your BuildRun resource using the spec.build.spec field. This builds an image without creating and maintaining a dedicated Build custom resource. The following example shows a BuildRun custom resource (CR) that configures the spec.build.spec field:
where
<path_to_image>- Specifies the path to the image file.
You cannot use the spec.build.name and spec.build.spec fields together in the same CR because they are mutually exclusive.
3.4. Parameter values definition for a build run Link kopierenLink in die Zwischenablage kopiert!
You can define values for build strategy parameters in your BuildRun custom resource (CR). Values set in the BuildRun resource override any values with the same name in the Build resource.
In the following example, the cache value in the BuildRun overrides the cache value in the Build resource:
where
<your_build>-
Specifies the name of the
BuildCR. <your_namespace>-
Specifies the namespace of the
BuildCR. <your_strategy>-
Specifies the strategy used for the
BuildCR.
where
<your_buildrun>-
Specifies the name of the
BuildrunCR. <your_namespace>-
Specifies the namespace of the
BuildrunCR. <your_build>-
Specifies the name of the
Build.
3.5. Service account definition Link kopierenLink in die Zwischenablage kopiert!
Define a service account in your BuildRun resource to provide access to the secrets referenced by your Build resource, as shown in the following example.
spec.serviceAccount:: Defines the name of the generated service account corresponding to the name of theBuildRunresource. You can also set the value to".generate"to generate the service account during runtime.NoteWhen you do not define the service account, the
BuildRunresource uses thepipelineservice account if it exists in the namespace. Otherwise, theBuildRunresource uses thedefaultservice account.
3.6. Retention parameters definition for a build run Link kopierenLink in die Zwischenablage kopiert!
Use retention parameters in your BuildRun custom resource (CR) to automatically delete completed build runs. In your BuildRun custom resource (CR), use the following retention parameters:
-
retention.ttlAfterFailed: Duration a failed build run remains before deletion. -
retention.ttlAfterSucceeded: Duration a successful build run remains before deletion.
The following example shows how to define retention parameters in your BuildRun CR:
If you have defined a retention parameter in both BuildRun and Build CRs, the value defined in the BuildRun CR overrides the value of the retention parameter defined in the Build CR.
3.7. Volumes definition for a build run Link kopierenLink in die Zwischenablage kopiert!
Define volumes in your BuildRun custom resource (CR) to override the volumes in the BuildStrategy resource. If a volume isn’t overridden, the build run fails. If both Build and BuildRun override the same volume, the value in BuildRun takes precedence.
The following example shows a BuildRun CR that uses the volumes field:
where:
- <build_name>
-
Specifies the name of the
BuildrunCR. - <buildrun_name>
-
Specifies the name of the
BuildCR. - <volume_name>
-
Specifies the name of the
volumeof theBuildCR. - <configmap_name>
-
Specifies the name of the
ConfigMapof theBuildCR.
3.8. Environment variables definition Link kopierenLink in die Zwischenablage kopiert!
You can set environment variables in your BuildRun custom resource (CR). These variables pass information to the build container. You can use literal values or the Kubernetes downward API.
The following example shows how to define environment variables:
where:
env.name-
Defines the names of the environment variables in the
BuildRunCR. env.value-
Defines the values of the environment variables in the
BuildRunCR.
The following example shows a BuildRun resource that uses the Kubernetes downward API to expose a pod as an environment variable:
where:
- <pod_name>
- Specifies the name of the pod.
The following example shows a BuildRun resource that uses the Kubernetes downward API to expose a container as an environment variable:
where:
- <my_container>
- Specifies the name of the container.
3.9. Build run status Link kopierenLink in die Zwischenablage kopiert!
Monitor the progress and completion of your image builds by checking the status of the BuildRun custom resource (CR). A BuildRun CR stores status information in the status.conditions field. This field includes the status, the reason for that status, and a descriptive message. For example, a Succeeded condition type means the build finished successfully.
The following examples show how to view the status of a specific BuildRun CR.
- Unknown status
-
An
Unknownstatus indicates the build is still starting or in progress. The following example shows aBuildRunwithUnknownstatus:
oc get buildrun buildah-buildrun-mp99r
$ oc get buildrun buildah-buildrun-mp99r
Example output:
NAME SUCCEEDED REASON STARTTIME COMPLETIONTIME buildah-buildrun-mp99r Unknown Unknown 1s
NAME SUCCEEDED REASON STARTTIME COMPLETIONTIME
buildah-buildrun-mp99r Unknown Unknown 1s
- True status
-
A
Truestatus indicates that the build completed successfully. The following example shows a BuildRun` withTruestatus:
oc get buildrun buildah-buildrun-mp99r
$ oc get buildrun buildah-buildrun-mp99r
Example output:
NAME SUCCEEDED REASON STARTTIME COMPLETIONTIME buildah-buildrun-mp99r True Succeeded 29m 20m
NAME SUCCEEDED REASON STARTTIME COMPLETIONTIME
buildah-buildrun-mp99r True Succeeded 29m 20m
A BuildRun CR stores the status-related information in the status.conditions field. For example, a condition with the type Succeeded indicates that resources have successfully completed their operation. The status.conditions field includes significant information like status, reason, and message for the BuildRun CR.
3.9.1. Build run statuses description Link kopierenLink in die Zwischenablage kopiert!
A BuildRun custom resource (CR) can have different statuses during the image building process. Track the state of your build using the status field.
The following table covers the different statuses of a build run:
| Status | Cause | Description |
|---|---|---|
|
|
|
The |
|
|
|
The controller validates and starts the |
|
|
| The user has requested to cancel the build run. This request triggers the build run controller to make a request for canceling the related task runs. Cancellation is still under process when this status is present. |
|
|
|
The pod for the |
|
|
|
The |
|
|
|
The execution of the |
|
|
|
The strategy type defined in the |
|
|
| The referenced cluster-scoped strategy was not found in the cluster. |
|
|
| The referenced namespace-scoped strategy was not found in the cluster. |
|
|
|
Setting the |
|
|
|
The |
|
|
|
The generation of a |
|
|
|
You have not provided any value for some parameters that are defined in the build strategy without any default. You must provide the values for those parameters in the |
|
|
| A value for a system parameter was provided, which is not allowed. |
|
|
| A value for a parameter was provided that is not defined in the build strategy. |
|
|
| The system detected an incorrectly typed build strategy parameter value. For example, if the parameter is defined as an array or a string in the build strategy, you must provide a set of values or a direct value accordingly. |
|
|
|
A value for a parameter contained more than one of these values: |
|
|
|
An item inside the values of an array parameter contained none of these values: |
|
|
|
A value for a parameter contained a |
|
|
|
A value for a parameter contained a |
|
|
| The referenced service account was not found in the cluster. |
|
|
|
The referenced build in the |
|
|
|
The referenced build in the |
|
|
|
The |
|
|
|
The defined build run name in the |
|
|
|
The |
|
|
|
The defined |
|
|
|
The defined |
|
|
| The build run pod was evicted from the node it was running on. |
3.9.2. Failed build runs Link kopierenLink in die Zwischenablage kopiert!
If a build fails, check the status.failureDetails field in the BuildRun custom resource (CR). This field provides the error message, the reason for the failure, and the specific container or pod where the error occurred. You can see the message and reason for failure only if it is defined in your build strategy.
The following example shows a failed build run:
The status.failureDetails field also provides error details for all operations related to Git.
3.9.3. Step results in build run status Link kopierenLink in die Zwischenablage kopiert!
After a BuildRun custom resource (CR) completes its execution, the .status field contains the .status.taskResults result emitted from the steps generated by the build run controller. The result includes the image digest or the commit SHA of the source code that is used for building the image. In a BuildRun CR, the .status.sources field contains the result from the execution of source steps and the .status.output field contains the result from the execution of output steps.
The following example shows a BuildRun CR with step results for a Git source:
The following example shows a BuildRun CR with step results for a local source code:
You get to see the digest and size of the output image only if it is defined in your build strategy.
3.9.4. Build snapshot Link kopierenLink in die Zwischenablage kopiert!
A build snapshot records the exact configuration used for a specific build run.
When a build run reconciles, the status.buildSpec field in the BuildRun custom resource (CR) updates. This field stores a complete copy of the original Build specification used for that specific image build. You can use this snapshot to verify the settings used during execution, even if the original Build CR changes later.
3.10. Relationship of build run with Tekton tasks Link kopierenLink in die Zwischenablage kopiert!
A BuildRun uses Tekton TaskRun resources to build your image. The TaskRun follows the steps defined in your build strategy until the build finishes or fails.
When you create a BuildRun, the build controller starts a new TaskRun. The BuildRun resource assigns the task of image construction to this TaskRun. The TaskRun then runs every step defined in your build strategy.
3.11. Build run cancellation Link kopierenLink in die Zwischenablage kopiert!
To stop an active BuildRun resource, set the state field of the BuildRun resource to BuildRunCanceled. Canceling a BuildRun also cancels the underlying TaskRun resource.
The following example shows a canceled build run for a BuildRun resource:
3.12. Automatic build run deletion Link kopierenLink in die Zwischenablage kopiert!
Automatically manage the lifecycle of build runs by defining retention and TTL parameters.
Add the following retention parameters in the build or buildrun specification to automatically delete a build run:
buildrunTTL parameters: Ensures that build runs only exist for a defined duration of time after completion.-
buildrun.spec.retention.ttlAfterFailed: The build run is deleted if the specified time has passed and the build run has failed. -
buildrun.spec.retention.ttlAfterSucceeded: The build run is deleted if the specified time has passed and the build run has succeeded.
-
buildTTL parameters: Ensures that build runs for a build only exist for a defined duration of time after completion.-
build.spec.retention.ttlAfterFailed: The build run is deleted if the specified time has passed and the build run has failed for the build. -
build.spec.retention.ttlAfterSucceeded: The build run is deleted if the specified time has passed and the build run has succeeded for the build.
-
buildlimit parameters: Ensures that only a limited number of succeeded or failed build runs can exist for a build.-
build.spec.retention.succeededLimit: Defines the number of succeeded build runs that can exist for the build. -
build.spec.retention.failedLimit: Defines the number of failed build runs that can exist for the build.
-
3.13. Pod configuration Link kopierenLink in die Zwischenablage kopiert!
Configure pod scheduling and placement for Builds by using optional BuildRun Custom Resource (CR) fields.
Use the following fields to configure Builds pods:
-
spec.tolerations: Specifies pod tolerations. Note: Only the NoSchedule taint effect is supported. -
spec.nodeSelector: Specifies the nodes where the pod must run. -
spec.schedulerName: Specifies a custom scheduler for the pod.
If you define these fields in both the Build and BuildRun CRs, the BuildRun values take priority.