diff --git a/docs/build.md b/docs/build.md index c18a440ec2..7da92e2364 100644 --- a/docs/build.md +++ b/docs/build.md @@ -83,7 +83,7 @@ The `Build` definition supports the following fields: A `Build` resource can specify a Git source, together with other parameters like: - `source.credentials.name` - For private repositories, the name is a reference to an existing secret on the same namespace containing the `ssh` data. -- `source.revision` - An specific revision to select from the source repository, this can be a commit or branch name. +- `source.revision` - An specific revision to select from the source repository, this can be a commit or branch name. If not defined, it will fallback to the git repository default branch. - `source.contextDir` - For repositories where the source code is not located at the root folder, you can specify this path here. Currently, only supported by `buildah`, `kaniko` and `buildpacks` build strategies. By default, the Build controller will validate that the Git repository exists. If the validation is not desired, users can define the `build.shipwright.io/verify.repository` annotation with `false`. For example: diff --git a/pkg/reconciler/buildrun/resources/taskrun.go b/pkg/reconciler/buildrun/resources/taskrun.go index f38ba9d2bc..0cac734612 100644 --- a/pkg/reconciler/buildrun/resources/taskrun.go +++ b/pkg/reconciler/buildrun/resources/taskrun.go @@ -180,7 +180,10 @@ func GenerateTaskRun( strategy buildv1alpha1.BuilderStrategy, ) (*v1beta1.TaskRun, error) { - revision := "master" + // Set revision to empty if the field is not specified in the Build. + // This will force Tekton Controller to do a git symbolic-link to HEAD + // giving back the default branch of the repository + revision := "" if build.Spec.Source.Revision != nil { revision = *build.Spec.Source.Revision } diff --git a/pkg/reconciler/buildrun/resources/taskrun_test.go b/pkg/reconciler/buildrun/resources/taskrun_test.go index 2bdf68d3c3..9b60f232ed 100644 --- a/pkg/reconciler/buildrun/resources/taskrun_test.go +++ b/pkg/reconciler/buildrun/resources/taskrun_test.go @@ -121,7 +121,7 @@ var _ = Describe("GenerateTaskrun", func() { namespace = "build-test" contextDir = "src" - revision = "master" + revision = "" builderImage = &buildv1alpha1.Image{ ImageURL: "heroku/buildpacks:18", }