Ce contenu n'est pas disponible dans la langue sélectionnée.
Chapter 3. Configuring build runs
In a BuildRun custom resource (CR), you can configure a build run by defining the build reference, build specification, parameter values, service account, output, retention parameters, and volumes to configure a build run. You can also configure build pods by using a Build CR.
A BuildRun resource is available for use within a namespace.
To configure a build run, create a BuildRun resource YAML file and apply it to the OpenShift Container Platform cluster.
3.1. Configurable fields in build run Copier lienLien copié sur presse-papiers!
You can use the following required and optional 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 |
| 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 Copier lienLien copié sur presse-papiers!
You can 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 CR that configures the spec.build.name field:
3.3. Build specification definition Copier lienLien copié sur presse-papiers!
You can embed a complete build specification into your BuildRun resource using the spec.build.spec field. By embedding specifications, you can build an image without creating and maintaining a dedicated Build custom resource. The following example shows a BuildRun CR that configures the spec.build.spec field:
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 Copier lienLien copié sur presse-papiers!
You can specify values for the build strategy parameters in your BuildRun CR. If you have provided a value for a parameter that is also defined in the Build resource with the same name, then the value defined in the BuildRun resource takes priority.
In the following example, the value of the cache parameter in the BuildRun resource overrides the value of the cache parameter, which is defined in the Build resource:
3.5. Service account definition Copier lienLien copié sur presse-papiers!
You can define a service account in your BuildRun resource. The service account hosts all secrets referenced in your Build resource, as shown in the following example:
- 1
- You can also set the value of the
spec.serviceAccountfield to".generate"to generate the service account during runtime. The name of the generated service account corresponds with the name of theBuildRunresource.
When you do not define the service account, the BuildRun resource uses the pipeline service account if it exists in the namespace. Otherwise, the BuildRun resource uses the default service account.
3.6. Retention parameters definition for a build run Copier lienLien copié sur presse-papiers!
You can specify the duration for which a completed build run can exist in your BuildRun resource. Retention parameters provide a way to clean your BuildRun instances automatically. You can set the value of the following retention parameters in your BuildRun CR:
-
retention.ttlAfterFailed: Specifies the duration for which a failed build run can exist -
retention.ttlAfterSucceeded: Specifies the duration for which a successful build run can exist
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 Copier lienLien copié sur presse-papiers!
You can define volumes in your BuildRun CR. The defined volumes override the volumes specified in the BuildStrategy resource. If a volume is not overridden, then the build run fails.
In case the Build and BuildRun resources override the same volume, the volume defined in the BuildRun resource is used for overriding.
The following example shows a BuildRun CR that uses the volumes field:
3.8. Environment variables definition Copier lienLien copié sur presse-papiers!
You can use environment variables in your BuildRun CR based on your needs. The following example shows how to define environment variables:
Example: Defining a BuildRun resource with environment variables
The following example shows a BuildRun resource that uses the Kubernetes downward API to expose a pod as an environment variable:
Example: Defining a BuildRun resource to expose a pod as an environment variable
The following example shows a BuildRun resource that uses the Kubernetes downward API to expose a container as an environment variable:
Example: Defining a BuildRun resource to expose a container as an environment variable
3.9. Build run status Copier lienLien copié sur presse-papiers!
The BuildRun resource updates whenever the image building status changes, as shown in the following examples:
Example: BuildRun with Unknown status
oc get buildrun buildah-buildrun-mp99r
$ oc get buildrun buildah-buildrun-mp99r
NAME SUCCEEDED REASON STARTTIME COMPLETIONTIME
buildah-buildrun-mp99r Unknown Unknown 1s
Example: BuildRun with True status
oc get buildrun buildah-buildrun-mp99r
$ oc get buildrun buildah-buildrun-mp99r
NAME SUCCEEDED REASON STARTTIME COMPLETIONTIME
buildah-buildrun-mp99r True Succeeded 29m 20m
A BuildRun resource 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 resource.
3.9.1. Build run statuses description Copier lienLien copié sur presse-papiers!
A BuildRun custom resource (CR) can have different statuses during the image building process. The following table covers the different statuses of a build run:
| Status | Cause | Description |
|---|---|---|
|
|
|
The |
|
|
|
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. |
|
|
| A value was provided for a build strategy parameter with the wrong type. 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 Copier lienLien copié sur presse-papiers!
When a build run fails, you can check the status.failureDetails field in your BuildRun CR to identify the exact point where the failure happened in the pod or container. The status.failureDetails field includes an error message and a reason for the failure. You only see the message and reason for failure if they are 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 Copier lienLien copié sur presse-papiers!
After a BuildRun resource 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 resource, 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 resource with step results for a Git source:
Example: A BuildRun resource with step results for a Git source
The following example shows a BuildRun resource with step results for a local source code:
Example: A BuildRun resource 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 Copier lienLien copié sur presse-papiers!
For each build run reconciliation, the buildSpec field in the status of the BuildRun resource updates if an existing task run is part of that build run.
During this update, a Build resource snapshot generates and embeds into the status.buildSpec field of the BuildRun resource. Due to this, the buildSpec field contains an exact copy of the original Build specification, which was used to execute a particular image build. By using the build snapshot, you can see the original Build resource configuration.
3.10. Relationship of build run with Tekton tasks Copier lienLien copié sur presse-papiers!
The BuildRun resource delegates the task of image construction to the Tekton TaskRun resource, which runs all steps until either the completion of the task, or a failure occurs in the task.
During the build run reconciliation, the build run controller generates a new TaskRun resource. The controller embeds the required steps for a build run execution in the TaskRun resource. The embedded steps are defined in your build strategy.
3.11. Build run cancellation Copier lienLien copié sur presse-papiers!
You can cancel an active BuildRun instance by setting its state to BuildRunCanceled. When you cancel a BuildRun instance, the underlying TaskRun resource is also marked as canceled.
The following example shows a canceled build run for a BuildRun resource:
3.12. Automatic build run deletion Copier lienLien copié sur presse-papiers!
To automatically delete a build run, you can add the following retention parameters in the build or buildrun specification:
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 Copier lienLien copié sur presse-papiers!
You can use the following optional BuildRun CR fields to configure Builds pods:
The
spec.tolerationsfield specifies the tolerations for the Builds pod with the following limitation:-
Only the
NoScheduletaint effect is supported.
-
Only the
-
The
spec.nodeSelectorfield specifies which nodes the Builds pod should run on. -
The
spec.schedulerNamefield specifies the scheduler for the Builds pod.
If the fields are specified in both the Build and BuildRun CRs, the values in BuildRun CR are used.