Skip to content

Commit

Permalink
Add the git resource ref to the ResourceResult for git resources.
Browse files Browse the repository at this point in the history
This includes the full name of the git resource in the resource result for
git resources. We pass this along in the environment variable already, this
includes it back in the resource result so we can tie the commit sha and
branch name in the result.

Right now Task results contain the exact commit that was cloned from any git
resource inputs, but the "resourceref" field is empty. That makes it hard to
tell which repo was cloned after. In the case of multiple inputs, there is
no way to tell which result corresponds to which.
  • Loading branch information
dlorenc authored and tekton-robot committed Mar 23, 2020
1 parent 7389207 commit e395279
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cmd/git-init/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ package main

import (
"flag"
"os"

v1alpha1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
"github.com/tektoncd/pipeline/pkg/git"
"github.com/tektoncd/pipeline/pkg/termination"
"go.uber.org/zap"
Expand Down Expand Up @@ -61,10 +63,14 @@ func main() {
if err != nil {
logger.Fatalf("Error parsing commit of git repository: %s", err)
}
resourceName := os.Getenv("TEKTON_RESOURCE_NAME")
output := []v1alpha1.PipelineResourceResult{
{
Key: "commit",
Value: commit,
ResourceRef: v1beta1.PipelineResourceRef{
Name: resourceName,
},
},
}

Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.13

require (
cloud.google.com/go v0.47.0 // indirect
cloud.google.com/go/storage v1.0.0
contrib.go.opencensus.io/exporter/stackdriver v0.12.8 // indirect
github.com/GoogleCloudPlatform/cloud-builders/gcs-fetcher v0.0.0-20191203181535-308b93ad1f39
github.com/cloudevents/sdk-go/v2 v2.0.0-preview6
Expand Down Expand Up @@ -42,6 +43,7 @@ require (
golang.org/x/time v0.0.0-20191024005414-555d28b269f0 // indirect
golang.org/x/tools v0.0.0-20200214144324-88be01311a71 // indirect
gomodules.xyz/jsonpatch/v2 v2.1.0 // indirect
google.golang.org/api v0.15.0
google.golang.org/appengine v1.6.5 // indirect
k8s.io/api v0.17.3
k8s.io/apiextensions-apiserver v0.17.3 // indirect
Expand Down
4 changes: 4 additions & 0 deletions test/kaniko_task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ func TestKanikoTaskRun(t *testing.T) {
case "commit":
commit = rr.Value
}
// Every resource should have a ref with a name
if rr.ResourceRef.Name == "" {
t.Errorf("Resource ref not set for %v in TaskRun: %v", rr, tr)
}
}
if digest == "" {
t.Errorf("Digest not found in TaskRun.Status: %v", tr.Status)
Expand Down

0 comments on commit e395279

Please sign in to comment.