|
1 |
| -= Preventing redundant rebuilds |
| 1 | += Preventing redundant builds |
2 | 2 |
|
| 3 | +{ProductName} rebuilds the component when new pull requests (PRs) include changes to that component. This behavior helps you identify any issues the PR might cause before merging it. |
| 4 | + |
| 5 | +By default, {ProductName} configures pipelines to rebuild a component _only_ if a PR includes changes to that component. This configuration prevents redundant rebuilds in repositories that contain multiple components. |
| 6 | + |
| 7 | +However, depending on the structure of your repository and the dependencies of your component, you may want to adjust the default configuration for rebuilds to better suit your needs. In particular, the default configuration might still rebuild a component too often. You can change this behavior by editing the `on-cel-expression` annotation. |
| 8 | + |
| 9 | +.Procedure |
| 10 | + |
| 11 | +To prevent redundant builds of a component, complete the following steps. |
| 12 | + |
| 13 | +. Using your preferred IDE, in the repository of your component, open the `/.tekton/<name of component>-on-pull-request.yaml` file and find the`on-cel-expression` annotation. |
| 14 | ++ |
| 15 | +Example: |
| 16 | ++ |
| 17 | +---- |
| 18 | +pipelinesascode.tekton.dev/on-cel-expression: event == "pull_request" && target_branch |
| 19 | + == "main" && ( "my-component/***".pathChanged() || ".tekton/my-component-sample-pull-request.yaml".pathChanged() |
| 20 | + || "root-docker/Dockerfile".pathChanged() ) |
| 21 | +---- |
| 22 | ++ |
| 23 | +. Set the value as the path or paths that you want to trigger rebuilds. PRs with changes to files in those paths will cause {ProductName} to rebuild the component. |
| 24 | ++ |
| 25 | +Example: |
| 26 | ++ |
| 27 | +---- |
| 28 | +pipelinesascode.tekton.dev/on-cel-expression: event == "pull_request" && target_branch |
| 29 | + == "main" && ( "my-component/context/***".pathChanged() || ".tekton/my-component-pull-request.yaml".pathChanged() |
| 30 | + || "root-docker/Dockerfile".pathChanged() ) |
| 31 | +---- |
3 | 32 | +
|
4 |
| -NOTE: Is this builds or rebuilds? |
| 33 | +WARNING: Misconfiguring this value can prevent builds from starting or cause them to start at the wrong time. |
| 34 | ++ |
| 35 | +. Commit the changes. |
| 36 | +. Wait for {ProductName} to rebuild your component. |
| 37 | +
|
| 38 | +.Verification |
| 39 | +To verify that you have prevented redundant builds: |
| 40 | +
|
| 41 | +. Open a PR that modifies the component that you want {ProductName} to rebuild. |
| 42 | +. Wait for {ProductName} to rebuild your component. |
| 43 | +. Check the PipelineRuns page in {ProductName}. There should be only one new PipelineRun with the type as “Build.” Check its logs for the `build-container` task. They should only refer to the component you specified with `on-cel-expression`. |
| 44 | +
|
| 45 | +.Troubleshooting |
| 46 | +
|
| 47 | +If {ProductName} continues to rebuild your whole application for each new PR: |
| 48 | +
|
| 49 | +* Make sure you entered the right path as the value for `on-cel-expression`. |
| 50 | +* Make sure the logical operators between conditions in `on-cel-expression` are correct. For example, did you accidentally replace || with &&? |
| 51 | +* Make sure you merged the commit that changes `on-cel-expression`. |
| 52 | +
|
| 53 | +If builds are failing to start: |
| 54 | +
|
| 55 | +* Try the previously listed troubleshooting items. |
| 56 | +* If those ideas do not work, use `git revert` to restore your pipeline definition to its original state. |
| 57 | +
|
| 58 | +If builds are starting at the wrong time: |
| 59 | +
|
| 60 | +* For any component whose builds are starting at the wrong time, ensure that its `on-cel-expression` excludes all paths in the repo that are not associated with that component. |
0 commit comments