Skip to content

Enable relative TaskRefs within remote Pipelines #2149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions pkg/resolve/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package resolve
import (
"context"
"fmt"
"net/url"
"strings"

"github.com/openshift-pipelines/pipelines-as-code/pkg/matcher"
tektonv1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
Expand All @@ -19,6 +21,38 @@ func alreadyFetchedResource[T NamedItem](resources map[string]T, resourceName st
return false
}

func createTaskURL(eventPipelines map[string]*tektonv1.Pipeline, pipeline *tektonv1.Pipeline, tasks []string) ([]string, error) {
var pURL *url.URL
var err error
for ep := range eventPipelines {
// ensure the URL to be parsed matches the
// remote pipeline of the current PipelineRun
if eventPipelines[ep] != pipeline {
continue
}
pURL, err = url.Parse(ep)
if err != nil {
return tasks, err
}
pPath := strings.SplitAfter(pURL.Path, "/")
// pop the pipeline target path from the URL
pPath = pPath[:len(pPath)-1]
pURL.Path = strings.Join(pPath, "")
}
taskURLS := make([]string, len(tasks))
for i, t := range tasks {
tURL, err := url.Parse(t)
if err == nil && tURL.Scheme != "" && tURL.Host != "" {
taskURLS[i] = t
continue // it's already an absolute URL
}
tURL = pURL
tURL = tURL.JoinPath(t)
taskURLS[i] = tURL.String()
}
return taskURLS, nil
}

// resolveRemoteResources will get remote tasks or Pipelines from annotations.
//
// It already has some tasks or pipeline coming from the tekton directory stored in [types]
Expand Down Expand Up @@ -98,6 +132,11 @@ func resolveRemoteResources(ctx context.Context, rt *matcher.RemoteTasks, types
if err != nil {
return []*tektonv1.PipelineRun{}, fmt.Errorf("error getting remote task from pipeline annotations: %w", err)
}
// check for relative task references and assemble FQDNs
pipelineTasks, err = createTaskURL(fetchedResourcesForEvent.Pipelines, fetchedResourcesForPipelineRun.Pipeline, pipelineTasks)
if err != nil {
return []*tektonv1.PipelineRun{}, err
}
}
}

Expand Down
Loading