From 24edfc4794a619c14bac08fdf45853bfa7933b7e Mon Sep 17 00:00:00 2001 From: github-actions Date: Tue, 11 Jul 2023 23:14:46 +0000 Subject: [PATCH] chore: regenerated --- pkg/config/job/utilityconfig.go | 3 + .../inrepo/default_parameters.go | 27 +- pkg/triggerconfig/inrepo/load_pipelinerun.go | 576 +++++++++- .../inrepo/load_pipelinerun_test.go | 21 +- pkg/triggerconfig/inrepo/load_triggers.go | 57 +- .../inrepo/load_triggers_test.go | 3 +- pkg/triggerconfig/inrepo/params.go | 6 +- .../pipeline-finally-uses/README.md | 3 + .../pipeline-finally-uses/common.yaml | 15 + .../pipeline-finally-uses/expected.yaml | 302 +++++ .../pipeline-finally-uses/source.yaml | 21 + .../demo-deploy-kubectl.yaml | 35 + .../pipeline-load-refs-sub-dir/expected.yaml | 1003 +++++++++++++++++ .../pipeline-load-refs-sub-dir/kaniko.yaml | 63 ++ .../mydir/git-clone.yaml | 80 ++ .../pipeline-load-refs-sub-dir/source.yaml | 91 ++ .../unit-tests.yaml | 21 + .../demo-deploy-kubectl.yaml | 35 + .../pipeline-load-refs/expected.yaml | 1003 +++++++++++++++++ .../pipeline-load-refs/git-clone.yaml | 80 ++ .../pipeline-load-refs/kaniko.yaml | 63 ++ .../pipeline-load-refs/source.yaml | 91 ++ .../pipeline-load-refs/unit-tests.yaml | 21 + .../pipeline-missing-refs-fails/source.yaml | 91 ++ .../expected.yaml | 192 ++++ .../pipeline-tekton-git-resolver/source.yaml | 68 ++ .../pipeline/demo-deploy-kubectl.yaml | 35 + .../load_pipelinerun/pipeline/expected.yaml | 292 +++++ .../load_pipelinerun/pipeline/git-clone.yaml | 80 ++ .../load_pipelinerun/pipeline/kaniko.yaml | 63 ++ .../load_pipelinerun/pipeline/source.yaml | 89 ++ .../load_pipelinerun/pipeline/unit-tests.yaml | 21 + .../pr-load-refs/add-params.yaml | 21 + .../pr-load-refs/expected.yaml | 186 +++ .../pipeline-with-extra-params.yaml | 19 + .../load_pipelinerun/pr-load-refs/source.yaml | 17 + .../task-append-steps/expected.yaml | 178 +++ .../task-append-steps/source.yaml | 11 + .../task-disable-params/expected.yaml | 140 +++ .../task-disable-params/source.yaml | 122 ++ .../task-prepend-steps/expected.yaml | 178 +++ .../task-prepend-steps/source.yaml | 11 + .../task-without-params/expected.yaml | 268 +++++ .../task-without-params/source.yaml | 113 ++ .../load_pipelinerun/task/expected.yaml | 319 ++++++ .../load_pipelinerun/task/source.yaml | 196 ++++ .../load_pipelinerun/taskrun/expected.yaml | 243 ++++ .../load_pipelinerun/taskrun/source.yaml | 81 ++ .../load_pipelinerun/uses-all-steps/README.md | 3 + .../uses-all-steps/expected.yaml | 243 ++++ .../uses-all-steps/source.yaml | 11 + .../uses-custom-param-task/README.md | 1 + .../uses-custom-param-task/expected.yaml | 209 ++++ .../uses-custom-param-task/source.yaml | 30 + .../uses-custom-param/README.md | 1 + .../uses-custom-param/expected.yaml | 209 ++++ .../uses-custom-param/source.yaml | 30 + .../uses-issue-1234/README.md | 3 + .../uses-issue-1234/common.yaml | 15 + .../uses-issue-1234/expected.yaml | 190 ++++ .../uses-issue-1234/expected2.yaml | 190 ++++ .../uses-issue-1234/source.yaml | 15 + .../uses-issue-1234/source2.yaml | 12 + .../uses-steps-add-custom-explict/README.md | 5 + .../expected.yaml | 239 ++++ .../uses-steps-add-custom-explict/source.yaml | 35 + .../uses-steps-add-custom/README.md | 5 + .../uses-steps-add-custom/expected.yaml | 239 ++++ .../uses-steps-add-custom/source.yaml | 32 + .../uses-steps-custom-git/README.md | 3 + .../uses-steps-custom-git/expected.yaml | 469 ++++++++ .../uses-steps-custom-git/source.yaml | 26 + .../uses-steps-explicit/README.md | 5 + .../uses-steps-explicit/expected.yaml | 229 ++++ .../uses-steps-explicit/source.yaml | 20 + .../uses-steps-inherit-sidecar/README.md | 3 + .../uses-steps-inherit-sidecar/expected.yaml | 236 ++++ .../uses-steps-inherit-sidecar/source.yaml | 18 + .../uses-steps-multiple-copies/README.md | 3 + .../uses-steps-multiple-copies/expected.yaml | 251 +++++ .../uses-steps-multiple-copies/source.yaml | 26 + .../uses-steps-override-resources/README.md | 3 + .../expected.yaml | 257 +++++ .../uses-steps-override-resources/source.yaml | 20 + .../uses-steps-override-script/README.md | 8 + .../uses-steps-override-script/expected.yaml | 236 ++++ .../uses-steps-override-script/source.yaml | 24 + .../uses-steps-override/README.md | 8 + .../uses-steps-override/expected.yaml | 232 ++++ .../uses-steps-override/source.yaml | 39 + .../uses-steps-version-stream/README.md | 3 + .../uses-steps-version-stream/expected.yaml | 221 ++++ .../uses-steps-version-stream/source.yaml | 17 + .../uses-steps-with-sidecar-ws/README.md | 3 + .../uses-steps-with-sidecar-ws/expected.yaml | 264 +++++ .../uses-steps-with-sidecar-ws/source.yaml | 58 + .../uses-steps-with-sidecar/README.md | 3 + .../uses-steps-with-sidecar/expected.yaml | 236 ++++ .../uses-steps-with-sidecar/source.yaml | 24 + .../load_pipelinerun/uses-steps/README.md | 3 + .../load_pipelinerun/uses-steps/expected.yaml | 229 ++++ .../load_pipelinerun/uses-steps/source.yaml | 18 + .../uses-task-and-steps/README.md | 3 + .../uses-task-and-steps/expected.yaml | 307 +++++ .../uses-task-and-steps/source.yaml | 64 ++ .../inrepo/test_data/load_url/foo.yaml | 3 +- pkg/triggerconfig/inrepo/uses_resolver.go | 249 ++++ 107 files changed, 12133 insertions(+), 59 deletions(-) create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-finally-uses/README.md create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-finally-uses/common.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-finally-uses/expected.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-finally-uses/source.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-load-refs-sub-dir/demo-deploy-kubectl.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-load-refs-sub-dir/expected.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-load-refs-sub-dir/kaniko.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-load-refs-sub-dir/mydir/git-clone.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-load-refs-sub-dir/source.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-load-refs-sub-dir/unit-tests.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-load-refs/demo-deploy-kubectl.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-load-refs/expected.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-load-refs/git-clone.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-load-refs/kaniko.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-load-refs/source.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-load-refs/unit-tests.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-missing-refs-fails/source.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-tekton-git-resolver/expected.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-tekton-git-resolver/source.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline/demo-deploy-kubectl.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline/expected.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline/git-clone.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline/kaniko.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline/source.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline/unit-tests.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pr-load-refs/add-params.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pr-load-refs/expected.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pr-load-refs/pipeline-with-extra-params.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pr-load-refs/source.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/task-append-steps/expected.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/task-append-steps/source.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/task-disable-params/expected.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/task-disable-params/source.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/task-prepend-steps/expected.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/task-prepend-steps/source.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/task-without-params/expected.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/task-without-params/source.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/task/expected.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/task/source.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/taskrun/expected.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/taskrun/source.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-all-steps/README.md create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-all-steps/expected.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-all-steps/source.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-custom-param-task/README.md create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-custom-param-task/expected.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-custom-param-task/source.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-custom-param/README.md create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-custom-param/expected.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-custom-param/source.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-issue-1234/README.md create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-issue-1234/common.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-issue-1234/expected.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-issue-1234/expected2.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-issue-1234/source.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-issue-1234/source2.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-add-custom-explict/README.md create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-add-custom-explict/expected.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-add-custom-explict/source.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-add-custom/README.md create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-add-custom/expected.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-add-custom/source.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-custom-git/README.md create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-custom-git/expected.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-custom-git/source.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-explicit/README.md create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-explicit/expected.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-explicit/source.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-inherit-sidecar/README.md create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-inherit-sidecar/expected.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-inherit-sidecar/source.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-multiple-copies/README.md create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-multiple-copies/expected.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-multiple-copies/source.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-override-resources/README.md create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-override-resources/expected.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-override-resources/source.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-override-script/README.md create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-override-script/expected.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-override-script/source.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-override/README.md create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-override/expected.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-override/source.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-version-stream/README.md create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-version-stream/expected.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-version-stream/source.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-with-sidecar-ws/README.md create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-with-sidecar-ws/expected.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-with-sidecar-ws/source.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-with-sidecar/README.md create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-with-sidecar/expected.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-with-sidecar/source.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps/README.md create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps/expected.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps/source.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-task-and-steps/README.md create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-task-and-steps/expected.yaml create mode 100644 pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-task-and-steps/source.yaml create mode 100644 pkg/triggerconfig/inrepo/uses_resolver.go diff --git a/pkg/config/job/utilityconfig.go b/pkg/config/job/utilityconfig.go index cf65c01..9d4ce1d 100644 --- a/pkg/config/job/utilityconfig.go +++ b/pkg/config/job/utilityconfig.go @@ -35,4 +35,7 @@ type UtilityConfig struct { // CloneDepth is the depth of the clone that will be used. // A depth of zero will do a full clone. CloneDepth int `json:"clone_depth,omitempty"` + // IsResolvedWithUsesSyntax indicates how the pipeline was resolved. Used internally in lighthouse for determining + // if the pipeline syntax is deprecated. + IsResolvedWithUsesSyntax bool `json:"-"` } diff --git a/pkg/triggerconfig/inrepo/default_parameters.go b/pkg/triggerconfig/inrepo/default_parameters.go index 30d39e8..e02d9c4 100644 --- a/pkg/triggerconfig/inrepo/default_parameters.go +++ b/pkg/triggerconfig/inrepo/default_parameters.go @@ -4,6 +4,8 @@ import ( "context" "strings" + "github.com/tektoncd/pipeline/pkg/apis/config" + "github.com/pkg/errors" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" @@ -102,7 +104,6 @@ func DefaultPipelineParameters(prs *v1beta1.PipelineRun) (*v1beta1.PipelineRun, if prs.Annotations != nil && prs.Annotations[DefaultParameters] == "false" { return prs, nil } - ps := prs.Spec.PipelineSpec if ps == nil { return prs, nil @@ -125,15 +126,6 @@ func DefaultPipelineParameters(prs *v1beta1.PipelineRun) (*v1beta1.PipelineRun, } } - for i := range ps.Params { - param := &ps.Params[i] - if param.Type == "" { - param.Type = "string" - } - - ps.Params[i] = *param - } - for i := range ps.Finally { task := &ps.Finally[i] task.Params = addDefaultParameters(task.Params, defaultParameters) @@ -151,6 +143,8 @@ func DefaultPipelineParameters(prs *v1beta1.PipelineRun) (*v1beta1.PipelineRun, // lets validate to make sure its valid ctx := context.TODO() + // lets enable alpha fields + ctx = enableAlphaAPIFields(ctx) // lets avoid missing workspaces causing issues if len(prs.Spec.Workspaces) > 0 { @@ -175,6 +169,19 @@ func DefaultPipelineParameters(prs *v1beta1.PipelineRun) (*v1beta1.PipelineRun, return prs, nil } +func enableAlphaAPIFields(ctx context.Context) context.Context { + featureFlags, _ := config.NewFeatureFlagsFromMap(map[string]string{ + "enable-api-fields": "alpha", + }) + cfg := &config.Config{ + Defaults: &config.Defaults{ + DefaultTimeoutMinutes: 60, + }, + FeatureFlags: featureFlags, + } + return config.ToContext(ctx, cfg) +} + func addDefaultParameterSpecs(params []v1beta1.ParamSpec, defaults []v1beta1.ParamSpec) []v1beta1.ParamSpec { for _, dp := range defaults { found := false diff --git a/pkg/triggerconfig/inrepo/load_pipelinerun.go b/pkg/triggerconfig/inrepo/load_pipelinerun.go index 6a7d9c4..ff18b06 100644 --- a/pkg/triggerconfig/inrepo/load_pipelinerun.go +++ b/pkg/triggerconfig/inrepo/load_pipelinerun.go @@ -1,15 +1,21 @@ package inrepo import ( + "context" "fmt" + "io" + "net/http" "os" - "sigs.k8s.io/yaml" + "path/filepath" + "regexp" "strings" "time" "github.com/pkg/errors" + "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" tektonv1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "sigs.k8s.io/yaml" ) const ( @@ -37,26 +43,7 @@ type DefaultValues struct { Timeout *metav1.Duration } -func LoadTektonResourceAsPipelineRun(data []byte, ownerName string, repoName string, sha string) (*tektonv1beta1.PipelineRun, error) { - message := fmt.Sprintf("in repo %s/%s with sha %s", ownerName, repoName, sha) - prs := &tektonv1beta1.PipelineRun{} - // We're doing to replace any instances of versionStream with the versionStream version. Otherwise, we'd have to parse the whole pipeline spec and iterate over it. - // This is a jenkins-x specific functionality that it doesn't make sense for Tekton to support - pipelineString := strings.ReplaceAll(string(data), "versionStream", VersionStreamEnvVar(ownerName, repoName)) - err := yaml.Unmarshal([]byte(pipelineString), prs) - if err != nil { - return nil, errors.Wrapf(err, "failed to unmarshal PipelineRun YAML %s", message) - } - // Now we apply the default values - prs, err = DefaultPipelineParameters(prs) - if err != nil { - return nil, err - } - - return prs, err -} - -// NewDefaultValues creates a new default values +// NewDefaultValues creatse a new default values func NewDefaultValues() (*DefaultValues, error) { answer := &DefaultValues{ ServiceAccountName: os.Getenv("DEFAULT_PIPELINE_RUN_SERVICE_ACCOUNT"), @@ -74,6 +61,474 @@ func NewDefaultValues() (*DefaultValues, error) { return answer, nil } +// LoadTektonResourceAsPipelineRun loads a PipelineRun, Pipeline, Task or TaskRun and convert it to a PipelineRun +// if necessary +func LoadTektonResourceAsPipelineRun(resolver *UsesResolver, data []byte) (*tektonv1beta1.PipelineRun, error) { + if resolver.DefaultValues == nil { + var err error + resolver.DefaultValues, err = NewDefaultValues() + if err != nil { + return nil, errors.Wrapf(err, "failed to parse default values") + } + } + if resolver.Message == "" { + resolver.Message = fmt.Sprintf("in repo %s/%s with sha %s", resolver.OwnerName, resolver.RepoName, resolver.SHA) + } + message := resolver.Message + dir := resolver.Dir + kindPrefix := "kind:" + kind := "PipelineRun" + lines := strings.Split(string(data), "\n") + for _, line := range lines { + if !strings.HasPrefix(line, kindPrefix) { + continue + } + k := strings.TrimSpace(line[len(kindPrefix):]) + if k != "" { + kind = k + break + } + } + switch kind { + case "Pipeline": + pipeline := &tektonv1beta1.Pipeline{} + err := yaml.Unmarshal(data, pipeline) + if err != nil { + return nil, errors.Wrapf(err, "failed to unmarshal Pipeline YAML %s", message) + } + prs, err := ConvertPipelineToPipelineRun(pipeline, resolver.Message, resolver.DefaultValues) + if err != nil { + return prs, err + } + re, err := loadTektonRefsFromFilesPattern(prs) + if err != nil { + return prs, err + } + if re != nil { + prs, err = loadPipelineRunRefs(resolver, prs, dir, message, re) + if err != nil { + return prs, err + } + } + prs, err = inheritTaskSteps(resolver, prs) + if err != nil { + return prs, errors.Wrapf(err, "failed to inherit steps") + } + return DefaultPipelineParameters(prs) + + case "PipelineRun": + prs := &tektonv1beta1.PipelineRun{} + err := yaml.Unmarshal(data, prs) + if err != nil { + return nil, errors.Wrapf(err, "failed to unmarshal PipelineRun YAML %s", message) + } + + re, err := loadTektonRefsFromFilesPattern(prs) + if err != nil { + return prs, err + } + if re != nil { + prs, err = loadPipelineRunRefs(resolver, prs, dir, message, re) + if err != nil { + return prs, err + } + } + prs, err = inheritTaskSteps(resolver, prs) + if err != nil { + return prs, errors.Wrap(err, "failed to inherit steps") + } + return DefaultPipelineParameters(prs) + + case "Task": + task := &tektonv1beta1.Task{} + err := yaml.Unmarshal(data, task) + if err != nil { + return nil, errors.Wrapf(err, "failed to unmarshal Task YAML %s", message) + } + prs, err := ConvertTaskToPipelineRun(task, message, resolver.DefaultValues) + if err != nil { + return prs, err + } + re, err := loadTektonRefsFromFilesPattern(prs) + if err != nil { + return prs, err + } + if re != nil { + prs, err = loadPipelineRunRefs(resolver, prs, dir, message, re) + if err != nil { + return prs, err + } + } + prs, err = inheritTaskSteps(resolver, prs) + if err != nil { + return prs, errors.Wrapf(err, "failed to inherit steps") + } + defaultTaskName(prs) + return DefaultPipelineParameters(prs) + + case "TaskRun": + tr := &tektonv1beta1.TaskRun{} + err := yaml.Unmarshal(data, tr) + if err != nil { + return nil, errors.Wrapf(err, "failed to unmarshal TaskRun YAML %s", message) + } + prs, err := ConvertTaskRunToPipelineRun(tr, message, resolver.DefaultValues) + if err != nil { + return prs, err + } + re, err := loadTektonRefsFromFilesPattern(prs) + if err != nil { + return prs, err + } + if re != nil { + prs, err = loadPipelineRunRefs(resolver, prs, dir, message, re) + if err != nil { + return prs, err + } + } + prs, err = inheritTaskSteps(resolver, prs) + if err != nil { + return prs, errors.Wrapf(err, "failed to inherit steps") + } + defaultTaskName(prs) + return DefaultPipelineParameters(prs) + + default: + return nil, errors.Errorf("kind %s is not supported for %s", kind, message) + } +} + +func defaultTaskName(prs *tektonv1beta1.PipelineRun) { + ps := prs.Spec.PipelineSpec + if ps != nil && len(ps.Tasks) > 0 { + t := ps.Tasks[0] + if t.Name == "" { + ps.Tasks[0].Name = "default" + } + } +} + +// inheritTaskSteps allows Task steps to be prepended or appended if the annotations are present +func inheritTaskSteps(resolver *UsesResolver, prs *tektonv1beta1.PipelineRun) (*tektonv1beta1.PipelineRun, error) { + err := processUsesSteps(resolver, prs) + if err != nil { + return prs, errors.Wrap(err, "failed to process uses steps") + } + ps := prs.Spec.PipelineSpec + if ps == nil || len(ps.Tasks) == 0 { + return prs, nil + } + if prs.Annotations == nil { + return prs, nil + } + appendURL := prs.Annotations[AppendStepURL] + prependURL := prs.Annotations[PrependStepURL] + + var appendTask *tektonv1beta1.Task + var prependTask *tektonv1beta1.Task + + if appendURL != "" { + appendTask, err = loadTaskByURL(appendURL) + if err != nil { + return prs, errors.Wrapf(err, "failed to load append steps Task") + } + } + if prependURL != "" { + prependTask, err = loadTaskByURL(prependURL) + if err != nil { + return prs, errors.Wrapf(err, "failed to load prepend steps Task") + } + } + if prependTask != nil { + firstTask := &ps.Tasks[0] + if firstTask.TaskSpec != nil { + firstTask.TaskSpec.Steps = append(prependTask.Spec.Steps, firstTask.TaskSpec.Steps...) + } + } + if appendTask != nil { + lastTask := &ps.Tasks[len(ps.Tasks)-1] + lastTask.TaskSpec.Steps = append(lastTask.TaskSpec.Steps, appendTask.Spec.Steps...) + } + return prs, nil +} + +// processUsesSteps handles any step which has an image prefixed with "uses:" +func processUsesSteps(resolver *UsesResolver, prs *tektonv1beta1.PipelineRun) error { + ps := prs.Spec.PipelineSpec + if ps == nil { + return nil + } + tasksAndFinally := [][]v1beta1.PipelineTask{ + ps.Tasks, + ps.Finally, + } + for i := range tasksAndFinally { + pipelineTasks := tasksAndFinally[i] + if err := processUsesStepsHelper(resolver, prs, pipelineTasks); err != nil { + return err + } + } + return nil +} + +func processUsesStepsHelper(resolver *UsesResolver, prs *tektonv1beta1.PipelineRun, pipelineTasks []tektonv1beta1.PipelineTask) error { + for i := range pipelineTasks { + pt := &pipelineTasks[i] + if pt.TaskSpec != nil { + ts := &pt.TaskSpec.TaskSpec + clearStepTemplateImage := false + var steps []tektonv1beta1.Step + for j := range ts.Steps { + step := ts.Steps[j] + image := step.Image + if image == "" && ts.StepTemplate != nil { + // lets default to the step image so we can share uses across steps + image = ts.StepTemplate.Image + if strings.HasPrefix(image, "uses:") { + clearStepTemplateImage = true + } + } + if !strings.HasPrefix(image, "uses:") { + steps = append(steps, step) + continue + } + sourceURI := strings.TrimPrefix(image, "uses:") + + loc := &UseLocation{ + PipelineRunSpec: &prs.Spec, + PipelineSpec: prs.Spec.PipelineSpec, + PipelineTask: pt, + TaskName: pt.Name, + TaskSpec: ts, + } + replaceSteps, err := resolver.UsesSteps(sourceURI, pt.Name, step, ts, loc) + if err != nil { + return errors.Wrapf(err, "failed to resolve git URI %s for step %s", sourceURI, step.Name) + } + steps = append(steps, replaceSteps...) + } + ts.Steps = steps + if clearStepTemplateImage && ts.StepTemplate != nil { + ts.StepTemplate.Image = "" + } + } + } + return nil +} + +func loadTaskByURL(uri string) (*tektonv1beta1.Task, error) { + resp, err := http.Get(uri) // #nosec + if err != nil { + return nil, errors.Wrapf(err, "failed to read URL %s", uri) + } + defer resp.Body.Close() + + data, err := io.ReadAll(resp.Body) + if err != nil { + return nil, errors.Wrapf(err, "failed to read body from URL %s", uri) + } + + task := &tektonv1beta1.Task{} + err = yaml.Unmarshal(data, &task) + if err != nil { + return nil, errors.Wrapf(err, "failed to unmarshall YAML from URL %s", uri) + } + return task, nil +} + +// loadTektonRefsFromFilesPattern returns a regular expression matching the Pipeline/Task references we should load +// via the file system as separate local files +func loadTektonRefsFromFilesPattern(prs *tektonv1beta1.PipelineRun) (*regexp.Regexp, error) { + if prs.Annotations == nil { + return nil, nil + } + pattern := prs.Annotations[LoadFileRefPattern] + if pattern == "" { + return nil, nil + } + re, err := regexp.Compile(pattern) + if err != nil { + return nil, errors.Wrapf(err, "failed to parse annotation %s value %s as a regular expression", LoadFileRefPattern, pattern) + } + return re, nil +} + +func loadPipelineRunRefs(resolver *UsesResolver, prs *tektonv1beta1.PipelineRun, dir, message string, re *regexp.Regexp) (*tektonv1beta1.PipelineRun, error) { + // if we reference a local + if prs.Spec.PipelineSpec == nil && prs.Spec.PipelineRef != nil && prs.Spec.PipelineRef.Name != "" && re.MatchString(prs.Spec.PipelineRef.Name) { + pipelinePath := filepath.Join(dir, prs.Spec.PipelineRef.Name) + if !strings.HasSuffix(pipelinePath, ".yaml") { + pipelinePath += ".yaml" + } + data, err := resolver.GetData(pipelinePath, true) + if err != nil { + return prs, errors.Wrapf(err, "failed to find path %s in PipelineRun", pipelinePath) + } + if len(data) == 0 { + return prs, errors.Errorf("no YAML for path %s in PipelineRun", pipelinePath) + } + p := &tektonv1beta1.Pipeline{} + err = yaml.Unmarshal(data, p) + if err != nil { + return prs, errors.Wrapf(err, "failed to unmarshal Pipeline YAML file %s %s", pipelinePath, message) + } + prs.Spec.PipelineSpec = &p.Spec + prs.Spec.PipelineRef = nil + } + + if prs.Spec.PipelineSpec != nil { + err := loadTaskRefs(resolver, prs.Spec.PipelineSpec, dir, message, re) + if err != nil { + return prs, errors.Wrapf(err, "failed to load Task refs for %s", message) + } + } + return prs, nil +} + +func loadTaskRefs(resolver *UsesResolver, pipelineSpec *tektonv1beta1.PipelineSpec, dir, message string, re *regexp.Regexp) error { + for i := range pipelineSpec.Tasks { + t := &pipelineSpec.Tasks[i] + if t.TaskSpec == nil && t.TaskRef != nil && t.TaskRef.Name != "" && re.MatchString(t.TaskRef.Name) { + path := filepath.Join(dir, t.TaskRef.Name) + if !strings.HasSuffix(path, ".yaml") { + path += ".yaml" + } + data, err := resolver.GetData(path, false) + if err != nil { + return errors.Wrapf(err, "failed to find path %s in PipelineSpec", path) + } + if len(data) == 0 { + return errors.Errorf("no YAML for path %s in PipelineSpec", path) + } + t2 := &tektonv1beta1.Task{} + err = yaml.Unmarshal(data, t2) + if err != nil { + return errors.Wrapf(err, "failed to unmarshal Task YAML file %s %s", path, message) + } + t.TaskSpec = &tektonv1beta1.EmbeddedTask{ + TaskSpec: t2.Spec, + } + t.TaskRef = nil + } + } + return nil +} + +// ConvertPipelineToPipelineRun converts the Pipeline to a PipelineRun +func ConvertPipelineToPipelineRun(from *tektonv1beta1.Pipeline, message string, defaultValues *DefaultValues) (*tektonv1beta1.PipelineRun, error) { + prs := &tektonv1beta1.PipelineRun{ + TypeMeta: metav1.TypeMeta{ + Kind: "PipelineRun", + APIVersion: TektonAPIVersion, + }, + } + prs.Name = from.Name + prs.Annotations = from.Annotations + prs.Labels = from.Labels + + prs.Spec.PipelineSpec = &from.Spec + defaultValues.Apply(prs) + return prs, nil +} + +// ConvertTaskToPipelineRun converts the Task to a PipelineRun +func ConvertTaskToPipelineRun(from *tektonv1beta1.Task, message string, defaultValues *DefaultValues) (*tektonv1beta1.PipelineRun, error) { + prs := &tektonv1beta1.PipelineRun{ + TypeMeta: metav1.TypeMeta{ + Kind: "PipelineRun", + APIVersion: TektonAPIVersion, + }, + } + prs.Name = from.Name + prs.Annotations = from.Annotations + prs.Labels = from.Labels + + fs := &from.Spec + pipelineSpec := &tektonv1beta1.PipelineSpec{ + Description: "", + Resources: nil, + Tasks: []tektonv1beta1.PipelineTask{ + { + Name: from.Name, + TaskSpec: &tektonv1beta1.EmbeddedTask{TaskSpec: *fs}, + Resources: ToPipelineResources(fs.Resources), + Params: ToParams(fs.Params), + Workspaces: ToWorkspacePipelineTaskBindingsFromDeclarations(fs.Workspaces), + }, + }, + Params: fs.Params, + Workspaces: ToPipelineWorkspaceDeclarations(fs.Workspaces), + //Results: fs.Results, + Finally: nil, + } + prs.Spec.PipelineSpec = pipelineSpec + //prs.Spec.Resources = fs.Resources + prs.Spec.Workspaces = ToWorkspaceBindings(fs.Workspaces) + defaultValues.Apply(prs) + + // lets copy the params from the task -> pipeline -> pipelinerun + loc := &UseLocation{ + PipelineRunSpec: &prs.Spec, + PipelineSpec: pipelineSpec, + TaskName: from.Name, + TaskRunSpec: nil, + TaskSpec: fs, + } + UseParametersAndResults(context.TODO(), loc, fs) + return prs, nil +} + +// ConvertTaskRunToPipelineRun converts the TaskRun to a PipelineRun +func ConvertTaskRunToPipelineRun(from *tektonv1beta1.TaskRun, message string, defaultValues *DefaultValues) (*tektonv1beta1.PipelineRun, error) { + prs := &tektonv1beta1.PipelineRun{ + TypeMeta: metav1.TypeMeta{ + Kind: "PipelineRun", + APIVersion: TektonAPIVersion, + }, + } + prs.Name = from.Name + prs.Annotations = from.Annotations + prs.Labels = from.Labels + + fs := &from.Spec + params := fs.Params + var paramSpecs []tektonv1beta1.ParamSpec + if len(params) == 0 && fs.TaskSpec != nil { + paramSpecs = fs.TaskSpec.Params + if len(params) == 0 { + params = ToParams(paramSpecs) + } + } + if len(paramSpecs) == 0 { + paramSpecs = ToParamSpecs(params) + } + pipelineSpec := &tektonv1beta1.PipelineSpec{ + Description: "", + Resources: nil, + Tasks: []tektonv1beta1.PipelineTask{ + { + Name: from.Name, + TaskRef: fs.TaskRef, + TaskSpec: &tektonv1beta1.EmbeddedTask{TaskSpec: *fs.TaskSpec}, + //Resources: fs.Resources, + Params: params, + Workspaces: ToWorkspacePipelineTaskBindings(fs.Workspaces), + }, + }, + Params: paramSpecs, + Workspaces: nil, + Results: nil, + Finally: nil, + } + prs.Spec.PipelineSpec = pipelineSpec + prs.Spec.PodTemplate = fs.PodTemplate + //prs.Spec.Resources = fs.Resources + prs.Spec.ServiceAccountName = fs.ServiceAccountName + prs.Spec.Workspaces = fs.Workspaces + defaultValues.Apply(prs) + return prs, nil +} + // Apply adds any default values that are empty in the generated PipelineRun func (v *DefaultValues) Apply(prs *tektonv1beta1.PipelineRun) { if prs.Spec.ServiceAccountName == "" && v.ServiceAccountName != "" { @@ -99,6 +554,67 @@ func ToParams(params []tektonv1beta1.ParamSpec) []tektonv1beta1.Param { return answer } +// ToParamSpecs generates param specs from the params +func ToParamSpecs(params []tektonv1beta1.Param) []tektonv1beta1.ParamSpec { + var answer []tektonv1beta1.ParamSpec + for _, p := range params { + answer = append(answer, tektonv1beta1.ParamSpec{ + Name: p.Name, + // lets assume strings for now + Type: tektonv1beta1.ParamTypeString, + Description: "", + Default: nil, + }) + } + return answer +} + +// ToPipelineResources converts the task resources to piepline resources +func ToPipelineResources(resources *tektonv1beta1.TaskResources) *tektonv1beta1.PipelineTaskResources { + if resources == nil { + return nil + } + return &tektonv1beta1.PipelineTaskResources{ + Inputs: ToPipelineInputs(resources.Inputs), + Outputs: ToPipelineOutputs(resources.Inputs), + } +} + +// ToPipelineInputs converts the task resources into pipeline inputs +func ToPipelineInputs(inputs []tektonv1beta1.TaskResource) []tektonv1beta1.PipelineTaskInputResource { + var answer []tektonv1beta1.PipelineTaskInputResource + for _, from := range inputs { + answer = append(answer, ToPipelineInput(from)) + } + return answer +} + +// ToPipelineOutputs converts the task resources into pipeline outputs +func ToPipelineOutputs(inputs []tektonv1beta1.TaskResource) []tektonv1beta1.PipelineTaskOutputResource { + var answer []tektonv1beta1.PipelineTaskOutputResource + for _, from := range inputs { + answer = append(answer, ToPipelineOutput(from)) + } + return answer +} + +// ToPipelineInput converts the task resource into pipeline inputs +func ToPipelineInput(from tektonv1beta1.TaskResource) tektonv1beta1.PipelineTaskInputResource { + return tektonv1beta1.PipelineTaskInputResource{ + Name: from.Name, + Resource: from.ResourceDeclaration.Name, + From: nil, + } +} + +// ToPipelineOutput converts the task resource into pipeline outputs +func ToPipelineOutput(from tektonv1beta1.TaskResource) tektonv1beta1.PipelineTaskOutputResource { + return tektonv1beta1.PipelineTaskOutputResource{ + Name: from.Name, + Resource: from.ResourceDeclaration.Name, + } +} + // ToWorkspaceBindings converts the workspace declarations to workspaces bindings func ToWorkspaceBindings(workspaces []tektonv1beta1.WorkspaceDeclaration) []tektonv1beta1.WorkspaceBinding { var answer []tektonv1beta1.WorkspaceBinding @@ -115,6 +631,24 @@ func ToWorkspaceBinding(from tektonv1beta1.WorkspaceDeclaration) tektonv1beta1.W } } +// ToWorkspacePipelineTaskBindings converts the workspace bindings to pipeline task bindings +func ToWorkspacePipelineTaskBindings(workspaces []tektonv1beta1.WorkspaceBinding) []tektonv1beta1.WorkspacePipelineTaskBinding { + var answer []tektonv1beta1.WorkspacePipelineTaskBinding + for _, from := range workspaces { + answer = append(answer, ToWorkspacePipelineTaskBinding(from)) + } + return answer +} + +// ToWorkspacePipelineTaskBinding converts the workspace binding to a pipeline task binding +func ToWorkspacePipelineTaskBinding(from tektonv1beta1.WorkspaceBinding) tektonv1beta1.WorkspacePipelineTaskBinding { + return tektonv1beta1.WorkspacePipelineTaskBinding{ + Name: from.Name, + Workspace: from.Name, + SubPath: from.SubPath, + } +} + // ToWorkspacePipelineTaskBindingsFromDeclarations converts the workspace declarations to pipeline task bindings func ToWorkspacePipelineTaskBindingsFromDeclarations(workspaces []tektonv1beta1.WorkspaceDeclaration) []tektonv1beta1.WorkspacePipelineTaskBinding { var answer []tektonv1beta1.WorkspacePipelineTaskBinding diff --git a/pkg/triggerconfig/inrepo/load_pipelinerun_test.go b/pkg/triggerconfig/inrepo/load_pipelinerun_test.go index 18b0ebb..468375e 100644 --- a/pkg/triggerconfig/inrepo/load_pipelinerun_test.go +++ b/pkg/triggerconfig/inrepo/load_pipelinerun_test.go @@ -7,6 +7,9 @@ import ( "strings" "testing" + fbfake "github.com/jenkins-x/lighthouse-client/pkg/filebrowser/fake" + + "github.com/jenkins-x/lighthouse-client/pkg/filebrowser" "github.com/jenkins-x/lighthouse-client/pkg/util" "github.com/stretchr/testify/assert" @@ -27,6 +30,8 @@ func TestLoadPipelineRunTest(t *testing.T) { fs, err := os.ReadDir(sourceDir) require.NoError(t, err, "failed to read source Dir %s", sourceDir) + fileBrowser := fbfake.NewFakeFileBrowser("test_data", true) + // lets use a custom version stream sha os.Setenv("LIGHTHOUSE_VERSIONSTREAM_JENKINS_X_JX3_PIPELINE_CATALOG", "myversionstreamref") @@ -58,9 +63,23 @@ func TestLoadPipelineRunTest(t *testing.T) { continue } + sourceURL := filebrowser.GitHubURL + if name == "uses-steps-custom-git" { + sourceURL = "https://my.gitserver.com" + } + fileBrowsers, err := filebrowser.NewFileBrowsers(sourceURL, fileBrowser) require.NoError(t, err, "failed to create filebrowsers") + fc := filebrowser.NewFetchCache() + + resolver := &UsesResolver{ + FileBrowsers: fileBrowsers, + FetchCache: fc, + OwnerName: "myorg", + LocalFileResolve: true, + } dir := filepath.Join(sourceDir, name) + resolver.Dir = dir i := 0 for i <= 10 { @@ -85,7 +104,7 @@ func TestLoadPipelineRunTest(t *testing.T) { data, err := os.ReadFile(path) require.NoError(t, err, "failed to load "+message) - pr, err := LoadTektonResourceAsPipelineRun(data, "myorg", "myRepo", "someSha") + pr, err := LoadTektonResourceAsPipelineRun(resolver, data) if strings.HasSuffix(name, "-fails") { require.Errorf(t, err, "expected failure for test %s", name) diff --git a/pkg/triggerconfig/inrepo/load_triggers.go b/pkg/triggerconfig/inrepo/load_triggers.go index b2b44e8..b54326d 100644 --- a/pkg/triggerconfig/inrepo/load_triggers.go +++ b/pkg/triggerconfig/inrepo/load_triggers.go @@ -12,6 +12,7 @@ import ( "github.com/jenkins-x/lighthouse-client/pkg/util" + "github.com/jenkins-x/go-scm/scm" "github.com/jenkins-x/lighthouse-client/pkg/config" "github.com/jenkins-x/lighthouse-client/pkg/config/job" "github.com/jenkins-x/lighthouse-client/pkg/filebrowser" @@ -22,14 +23,6 @@ import ( "sigs.k8s.io/yaml" ) -var ( - // VersionStreamVersions allows you to register version stream values of ful repository names in the format - // `owner/name` mapping to the version SHA/branch/tag - VersionStreamVersions = map[string]string{} - - ignoreUsesCache = os.Getenv("NO_USES_CACHE") == "true" -) - // MergeTriggers merges the configuration with any `lighthouse.yaml` files in the repository func MergeTriggers(cfg *config.Config, pluginCfg *plugins.Configuration, fileBrowsers *filebrowser.FileBrowsers, fc filebrowser.FetchCache, cache *ResolverCache, ownerName string, repoName string, sha string) (bool, error) { repoConfig, err := LoadTriggerConfig(fileBrowsers, fc, cache, ownerName, repoName, sha) @@ -163,7 +156,7 @@ func loadConfigFile(filePath string, fileBrowsers *filebrowser.FileBrowsers, fc return nil, err } r.SetPipelineLoader(func(base *job.Base) error { - err = loadJobBaseFromSourcePath(data, base, ownerName, repoName, sourcePath, sha) + err = loadJobBaseFromSourcePath(data, fileBrowsers, fc, cache, base, ownerName, repoName, sourcePath, sha) if err != nil { return errors.Wrapf(err, "failed to load source for presubmit %s", r.Name) } @@ -188,7 +181,7 @@ func loadConfigFile(filePath string, fileBrowsers *filebrowser.FileBrowsers, fc return nil, err } r.SetPipelineLoader(func(base *job.Base) error { - err = loadJobBaseFromSourcePath(data, base, ownerName, repoName, sourcePath, sha) + err = loadJobBaseFromSourcePath(data, fileBrowsers, fc, cache, base, ownerName, repoName, sourcePath, sha) if err != nil { return errors.Wrapf(err, "failed to load source for postsubmit %s", r.Name) } @@ -219,7 +212,7 @@ func loadLocalFile(dir, name, sha string) ([]byte, error) { return nil, nil } -func loadJobBaseFromSourcePath(data []byte, j *job.Base, ownerName, repoName, path, sha string) error { +func loadJobBaseFromSourcePath(data []byte, fileBrowsers *filebrowser.FileBrowsers, fc filebrowser.FetchCache, cache *ResolverCache, j *job.Base, ownerName, repoName, path, sha string) error { if data == nil { _, err := url.ParseRequestURI(path) if err == nil { @@ -235,23 +228,33 @@ func loadJobBaseFromSourcePath(data []byte, j *job.Base, ownerName, repoName, pa return errors.Errorf("empty file file %s in repo %s/%s for sha %s", path, ownerName, repoName, sha) } - prs, err := LoadTektonResourceAsPipelineRun(data, ownerName, repoName, sha) + if strings.Contains(string(data), "image: uses:") { + j.IsResolvedWithUsesSyntax = true + } + + dir := filepath.Dir(path) + + message := fmt.Sprintf("in repo %s/%s with sha %s", ownerName, repoName, sha) + + usesResolver := &UsesResolver{ + FileBrowsers: fileBrowsers, + FetchCache: fc, + Cache: cache, + OwnerName: ownerName, + RepoName: repoName, + SHA: sha, + Dir: dir, + Message: message, + } + + prs, err := LoadTektonResourceAsPipelineRun(usesResolver, data) if err != nil { - return err + return errors.Wrapf(err, "failed to unmarshal YAML file %s in repo %s/%s with sha %s", path, ownerName, repoName, sha) } j.PipelineRunSpec = &prs.Spec return nil } -// VersionStreamEnvVar creates an environment variable name -func VersionStreamEnvVar(owner string, repo string) string { - envVar := strings.ToUpper(fmt.Sprintf("LIGHTHOUSE_VERSIONSTREAM_%s_%s", owner, repo)) - envVar = strings.ReplaceAll(envVar, "-", "_") - envVar = strings.ReplaceAll(envVar, " ", "_") - envVar = strings.ReplaceAll(envVar, ".", "_") - return envVar -} - func getPipelineFromURL(path string) ([]byte, error) { client := &http.Client{ CheckRedirect: redirectPolicyFunc, @@ -277,6 +280,16 @@ func getPipelineFromURL(path string) ([]byte, error) { return data, nil } +// IsScmNotFound returns true if the error is a not found error +func IsScmNotFound(err error) bool { + if err != nil { + // I think that we should instead rely on the http status (404) + // until jenkins-x go-scm is updated t return that in the error this works for github and gitlab + return strings.Contains(err.Error(), scm.ErrNotFound.Error()) + } + return false +} + func basicAuthGit() string { user := os.Getenv("GIT_USER") token := os.Getenv("GIT_TOKEN") diff --git a/pkg/triggerconfig/inrepo/load_triggers_test.go b/pkg/triggerconfig/inrepo/load_triggers_test.go index ccaf6a5..3af2966 100644 --- a/pkg/triggerconfig/inrepo/load_triggers_test.go +++ b/pkg/triggerconfig/inrepo/load_triggers_test.go @@ -86,7 +86,8 @@ func TestLoadJobFromURL(t *testing.T) { File("test_data/load_url/foo.yaml") j := &job.Base{} - err := loadJobBaseFromSourcePath(nil, j, "", "", "https://raw.githubusercontent.com/rawlingsj/test/master/foo.yaml", "") + fc := filebrowser.NewFetchCache() + err := loadJobBaseFromSourcePath(nil, nil, fc, NewResolverCache(), j, "", "", "https://raw.githubusercontent.com/rawlingsj/test/master/foo.yaml", "") assert.NoError(t, err, "should not have an error returned") assert.Equal(t, "jenkinsxio/chuck:0.0.1", j.PipelineRunSpec.PipelineSpec.Tasks[0].TaskSpec.Steps[0].Image, "image name for task is not correct") } diff --git a/pkg/triggerconfig/inrepo/params.go b/pkg/triggerconfig/inrepo/params.go index 40aa2e3..9c65d97 100644 --- a/pkg/triggerconfig/inrepo/params.go +++ b/pkg/triggerconfig/inrepo/params.go @@ -2,6 +2,7 @@ package inrepo import ( "context" + "fmt" "strings" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" @@ -33,7 +34,7 @@ func UseParametersAndResults(ctx context.Context, loc *UseLocation, uses *v1beta ps := loc.PipelineSpec if ps != nil { ps.Params = useParameterSpecs(ctx, ps.Params, parameterSpecs) - ps.Results = usePipelineResults(ps.Results, results) + ps.Results = usePipelineResults(ps.Results, results, loc.TaskName) ps.Workspaces = usePipelineWorkspaces(ps.Workspaces, uses.Workspaces) } pt := loc.PipelineTask @@ -169,7 +170,7 @@ func useParameterEnvVars(env []corev1.EnvVar, uses []v1beta1.Param) []corev1.Env return env } -func usePipelineResults(results []v1beta1.PipelineResult, uses []v1beta1.TaskResult) []v1beta1.PipelineResult { +func usePipelineResults(results []v1beta1.PipelineResult, uses []v1beta1.TaskResult, taskName string) []v1beta1.PipelineResult { for _, u := range uses { found := false for i := range results { @@ -186,6 +187,7 @@ func usePipelineResults(results []v1beta1.PipelineResult, uses []v1beta1.TaskRes results = append(results, v1beta1.PipelineResult{ Name: u.Name, Description: u.Description, + Value: *v1beta1.NewStructuredValues(fmt.Sprintf("$(tasks.%s.results.%s)", taskName, u.Name)), }) } } diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-finally-uses/README.md b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-finally-uses/README.md new file mode 100644 index 0000000..d1d5591 --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-finally-uses/README.md @@ -0,0 +1,3 @@ +## Reuse steps in a task inherit a 'finally' block + +This example shows how we can use `image: uses:sourceURI` and a `name: mystep` to include individually the steps in task diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-finally-uses/common.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-finally-uses/common.yaml new file mode 100644 index 0000000..c5f9e80 --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-finally-uses/common.yaml @@ -0,0 +1,15 @@ +apiVersion: tekton.dev/v1beta1 +kind: PipelineRun +metadata: + name: common +spec: + pipelineSpec: + tasks: + - name: common + taskSpec: + steps: + - image: common-image + name: common-build + env: + - name: FOO + value: foo diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-finally-uses/expected.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-finally-uses/expected.yaml new file mode 100644 index 0000000..bebc399 --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-finally-uses/expected.yaml @@ -0,0 +1,302 @@ +apiVersion: tekton.dev/v1beta1 +kind: PipelineRun +metadata: + creationTimestamp: null + name: cheese +spec: + params: + - name: BUILD_ID + value: "" + - name: JOB_NAME + value: "" + - name: JOB_SPEC + value: "" + - name: JOB_TYPE + value: "" + - name: PULL_BASE_REF + value: "" + - name: PULL_BASE_SHA + value: "" + - name: PULL_NUMBER + value: "" + - name: PULL_PULL_REF + value: "" + - name: PULL_PULL_SHA + value: "" + - name: PULL_REFS + value: "" + - name: REPO_NAME + value: "" + - name: REPO_OWNER + value: "" + - name: REPO_URL + value: "" + pipelineSpec: + finally: + - name: from-build-pack-finally + params: + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + taskSpec: + metadata: {} + params: + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: '''the kind of job: postsubmit or presubmit''' + name: JOB_TYPE + type: string + - description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + - description: git url to clone + name: REPO_URL + type: string + spec: null + stepTemplate: + env: + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + name: "" + resources: {} + steps: + - env: + - name: FOO + value: finally + image: common-image + name: common-build + resources: {} + params: + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: '''the kind of job: postsubmit or presubmit''' + name: JOB_TYPE + type: string + - description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + - description: git url to clone + name: REPO_URL + type: string + tasks: + - name: from-build-pack + params: + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + taskSpec: + metadata: {} + params: + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: '''the kind of job: postsubmit or presubmit''' + name: JOB_TYPE + type: string + - description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + - description: git url to clone + name: REPO_URL + type: string + spec: null + stepTemplate: + env: + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + name: "" + resources: {} + steps: + - env: + - name: FOO + value: foo + image: common-image + name: common-build + resources: {} +status: {} diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-finally-uses/source.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-finally-uses/source.yaml new file mode 100644 index 0000000..bbe60de --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-finally-uses/source.yaml @@ -0,0 +1,21 @@ +apiVersion: tekton.dev/v1beta1 +kind: PipelineRun +metadata: + name: cheese +spec: + pipelineSpec: + tasks: + - name: from-build-pack + taskSpec: + steps: + - image: uses:./test_data/load_pipelinerun/pipeline-finally-uses/common.yaml + name: common-build + finally: + - name: from-build-pack-finally + taskSpec: + steps: + - image: uses:./test_data/load_pipelinerun/pipeline-finally-uses/common.yaml + name: common-build + env: + - name: FOO + value: finally diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-load-refs-sub-dir/demo-deploy-kubectl.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-load-refs-sub-dir/demo-deploy-kubectl.yaml new file mode 100644 index 0000000..16085bb --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-load-refs-sub-dir/demo-deploy-kubectl.yaml @@ -0,0 +1,35 @@ +# This task deploys with kubectl apply -f +apiVersion: tekton.dev/v1beta1 +kind: Task +metadata: + name: demo-deploy-kubectl +spec: + params: + - name: path + description: Path to the manifest to apply + - name: yqArg + description: Okay this is a hack, but I didn't feel right hard-coding `-d1` down below + - name: yamlPathToImage + description: The path to the image to replace in the yaml manifest (arg to yq) + - name: imageURL + description: The URL of the image to deploy + workspaces: + - name: source + steps: + - name: replace-image + image: mikefarah/yq + command: ['yq'] + args: + - "w" + - "-i" + - "$(params.yqArg)" + - "$(params.path)" + - "$(params.yamlPathToImage)" + - "$(params.imageURL)" + - name: run-kubectl + image: lachlanevenson/k8s-kubectl + command: ['kubectl'] + args: + - 'apply' + - '-f' + - '$(params.path)' \ No newline at end of file diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-load-refs-sub-dir/expected.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-load-refs-sub-dir/expected.yaml new file mode 100644 index 0000000..501e7eb --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-load-refs-sub-dir/expected.yaml @@ -0,0 +1,1003 @@ +apiVersion: tekton.dev/v1beta1 +kind: PipelineRun +metadata: + annotations: + lighthouse.jenkins-x.io/loadFileRefs: .* + creationTimestamp: null + name: demo-pipeline +spec: + pipelineSpec: + params: + - default: gcr.io/christiewilson-catfactory + name: image-registry + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: '''the kind of job: postsubmit or presubmit''' + name: JOB_TYPE + type: string + - description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + - description: git url to clone + name: REPO_URL + type: string + tasks: + - name: fetch-from-git + params: + - name: url + value: https://github.com/GoogleContainerTools/skaffold + - name: revision + value: v0.32.0 + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + taskSpec: + metadata: {} + params: + - description: git url to clone + name: url + type: string + - default: master + description: git revision to checkout (branch, tag, sha, ref…) + name: revision + type: string + - default: "true" + description: defines if the resource should initialize and fetch the submodules + name: submodules + type: string + - default: "1" + description: performs a shallow clone where only the most recent commit(s) + will be fetched + name: depth + type: string + - default: "true" + description: defines if http.sslVerify should be set to true or false in + the global git config + name: sslVerify + type: string + - default: "" + description: subdirectory inside the "output" workspace to clone the git + repo into + name: subdirectory + type: string + - default: "false" + description: clean out the contents of the repo's destination directory + (if it already exists) before trying to clone the repo there + name: deleteExisting + type: string + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: '''the kind of job: postsubmit or presubmit''' + name: JOB_TYPE + type: string + - description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + - description: git url to clone + name: REPO_URL + type: string + results: + - description: The precise commit SHA that was fetched by this Task + name: commit + spec: null + stepTemplate: + env: + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + name: "" + resources: {} + steps: + - image: ko://github.com/tektoncd/pipeline/cmd/git-init + name: clone + resources: {} + script: |- + CHECKOUT_DIR="$(workspaces.output.path)/$(params.subdirectory)" + cleandir() { + # Delete any existing contents of the repo directory if it exists. + # + # We don't just "rm -rf $CHECKOUT_DIR" because $CHECKOUT_DIR might be "/" + # or the root of a mounted volume. + if [[ -d "$CHECKOUT_DIR" ]] ; then + # Delete non-hidden files and directories + rm -rf "$CHECKOUT_DIR"/* + # Delete files and directories starting with . but excluding .. + rm -rf "$CHECKOUT_DIR"/.[!.]* + # Delete files and directories starting with .. plus any other character + rm -rf "$CHECKOUT_DIR"/..?* + fi + } + if [[ "$(params.deleteExisting)" == "true" ]] ; then + cleandir + fi + /ko-app/git-init \ + -url "$(params.url)" \ + -revision "$(params.revision)" \ + -path "$CHECKOUT_DIR" \ + -sslVerify="$(params.sslVerify)" \ + -submodules="$(params.submodules)" \ + -depth="$(params.depth)" + cd "$CHECKOUT_DIR" + RESULT_SHA="$(git rev-parse HEAD | tr -d '\n')" + EXIT_CODE="$?" + if [ "$EXIT_CODE" != 0 ] + then + exit $EXIT_CODE + fi + # Make sure we don't add a trailing newline to the result! + echo -n "$RESULT_SHA" > $(results.commit.path) + workspaces: + - description: The git repo will be cloned onto the volume backing this workspace + name: output + workspaces: + - name: output + workspace: git-source + - name: skaffold-unit-tests + params: + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + runAfter: + - fetch-from-git + taskSpec: + metadata: {} + params: + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: '''the kind of job: postsubmit or presubmit''' + name: JOB_TYPE + type: string + - description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + - description: git url to clone + name: REPO_URL + type: string + spec: null + stepTemplate: + env: + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + name: "" + resources: {} + steps: + - env: + - name: GOPATH + value: /workspace/go + image: golang + name: run-tests + resources: {} + script: |- + # The intention behind this example Task is to run unit test, however we + # currently do nothing to ensure that a unit test issue doesn't cause this example + # to fail unnecessarily. In the future we could re-introduce the unit tests (since + # we are now pinning the version of Skaffold we pull) or use Tekton Pipelines unit tests. + echo "pass" + workingDir: $(workspaces.source.path) + workspaces: + - mountPath: /workspace/source/go/src/github.com/GoogleContainerTools/skaffold + name: source + workspaces: + - name: source + workspace: git-source + - name: build-skaffold-web + params: + - name: IMAGE + value: $(params.image-registry)/leeroy-web + - name: CONTEXT + value: examples/microservices/leeroy-web + - name: DOCKERFILE + value: $(workspaces.source.path)/examples/microservices/leeroy-web/Dockerfile + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + runAfter: + - skaffold-unit-tests + taskSpec: + metadata: {} + params: + - description: Name (reference) of the image to build. + name: IMAGE + - default: ./Dockerfile + description: Path to the Dockerfile to build. + name: DOCKERFILE + - default: ./ + description: The build context used by Kaniko. + name: CONTEXT + - default: "" + name: EXTRA_ARGS + - default: gcr.io/kaniko-project/executor:latest + description: The image on which builds will run + name: BUILDER_IMAGE + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: '''the kind of job: postsubmit or presubmit''' + name: JOB_TYPE + type: string + - description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + - description: git url to clone + name: REPO_URL + type: string + results: + - description: Digest of the image just built. + name: IMAGE_DIGEST + spec: null + stepTemplate: + env: + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + name: "" + resources: {} + steps: + - command: + - /kaniko/executor + - $(params.EXTRA_ARGS) + - --dockerfile=$(params.DOCKERFILE) + - --context=$(workspaces.source.path)/$(params.CONTEXT) + - --destination=$(params.IMAGE) + - --oci-layout-path=$(workspaces.source.path)/$(params.CONTEXT)/image-digest + env: + - name: DOCKER_CONFIG + value: /tekton/home/.docker + image: $(params.BUILDER_IMAGE) + name: build-and-push + resources: {} + securityContext: + runAsUser: 0 + workingDir: $(workspaces.source.path) + - args: + - -images=[{"name":"$(params.IMAGE)","type":"image","url":"$(params.IMAGE)","digest":"","OutputImageDir":"$(workspaces.source.path)/$(params.CONTEXT)/image-digest"}] + - -terminationMessagePath=$(params.CONTEXT)/image-digested + command: + - /ko-app/imagedigestexporter + image: ko://github.com/tektoncd/pipeline/cmd/imagedigestexporter + name: write-digest + resources: {} + securityContext: + runAsUser: 0 + workingDir: $(workspaces.source.path) + - image: stedolan/jq + name: digest-to-results + resources: {} + script: cat $(params.CONTEXT)/image-digested | jq '.[0].value' -rj | tee + /tekton/results/IMAGE_DIGEST + workingDir: $(workspaces.source.path) + workspaces: + - name: source + workspaces: + - name: source + workspace: git-source + - name: build-skaffold-app + params: + - name: IMAGE + value: $(params.image-registry)/leeroy-app + - name: CONTEXT + value: examples/microservices/leeroy-app + - name: DOCKERFILE + value: $(workspaces.source.path)/examples/microservices/leeroy-app/Dockerfile + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + runAfter: + - skaffold-unit-tests + taskSpec: + metadata: {} + params: + - description: Name (reference) of the image to build. + name: IMAGE + - default: ./Dockerfile + description: Path to the Dockerfile to build. + name: DOCKERFILE + - default: ./ + description: The build context used by Kaniko. + name: CONTEXT + - default: "" + name: EXTRA_ARGS + - default: gcr.io/kaniko-project/executor:latest + description: The image on which builds will run + name: BUILDER_IMAGE + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: '''the kind of job: postsubmit or presubmit''' + name: JOB_TYPE + type: string + - description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + - description: git url to clone + name: REPO_URL + type: string + results: + - description: Digest of the image just built. + name: IMAGE_DIGEST + spec: null + stepTemplate: + env: + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + name: "" + resources: {} + steps: + - command: + - /kaniko/executor + - $(params.EXTRA_ARGS) + - --dockerfile=$(params.DOCKERFILE) + - --context=$(workspaces.source.path)/$(params.CONTEXT) + - --destination=$(params.IMAGE) + - --oci-layout-path=$(workspaces.source.path)/$(params.CONTEXT)/image-digest + env: + - name: DOCKER_CONFIG + value: /tekton/home/.docker + image: $(params.BUILDER_IMAGE) + name: build-and-push + resources: {} + securityContext: + runAsUser: 0 + workingDir: $(workspaces.source.path) + - args: + - -images=[{"name":"$(params.IMAGE)","type":"image","url":"$(params.IMAGE)","digest":"","OutputImageDir":"$(workspaces.source.path)/$(params.CONTEXT)/image-digest"}] + - -terminationMessagePath=$(params.CONTEXT)/image-digested + command: + - /ko-app/imagedigestexporter + image: ko://github.com/tektoncd/pipeline/cmd/imagedigestexporter + name: write-digest + resources: {} + securityContext: + runAsUser: 0 + workingDir: $(workspaces.source.path) + - image: stedolan/jq + name: digest-to-results + resources: {} + script: cat $(params.CONTEXT)/image-digested | jq '.[0].value' -rj | tee + /tekton/results/IMAGE_DIGEST + workingDir: $(workspaces.source.path) + workspaces: + - name: source + workspaces: + - name: source + workspace: git-source + - name: deploy-app + params: + - name: imageURL + value: $(params.image-registry)/leeroy-app@$(tasks.build-skaffold-app.results.IMAGE_DIGEST) + - name: path + value: $(workspaces.source.path)/examples/microservices/leeroy-app/kubernetes/deployment.yaml + - name: yqArg + value: -d1 + - name: yamlPathToImage + value: spec.template.spec.containers[0].image + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + taskSpec: + metadata: {} + params: + - description: Path to the manifest to apply + name: path + - description: Okay this is a hack, but I didn't feel right hard-coding `-d1` + down below + name: yqArg + - description: The path to the image to replace in the yaml manifest (arg + to yq) + name: yamlPathToImage + - description: The URL of the image to deploy + name: imageURL + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: '''the kind of job: postsubmit or presubmit''' + name: JOB_TYPE + type: string + - description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + - description: git url to clone + name: REPO_URL + type: string + spec: null + stepTemplate: + env: + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + name: "" + resources: {} + steps: + - args: + - w + - -i + - $(params.yqArg) + - $(params.path) + - $(params.yamlPathToImage) + - $(params.imageURL) + command: + - yq + image: mikefarah/yq + name: replace-image + resources: {} + - args: + - apply + - -f + - $(params.path) + command: + - kubectl + image: lachlanevenson/k8s-kubectl + name: run-kubectl + resources: {} + workspaces: + - name: source + workspaces: + - name: source + workspace: git-source + - name: deploy-web + params: + - name: imageURL + value: $(params.image-registry)/leeroy-web@$(tasks.build-skaffold-web.results.IMAGE_DIGEST) + - name: path + value: $(workspaces.source.path)/examples/microservices/leeroy-web/kubernetes/deployment.yaml + - name: yqArg + value: -d1 + - name: yamlPathToImage + value: spec.template.spec.containers[0].image + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + taskSpec: + metadata: {} + params: + - description: Path to the manifest to apply + name: path + - description: Okay this is a hack, but I didn't feel right hard-coding `-d1` + down below + name: yqArg + - description: The path to the image to replace in the yaml manifest (arg + to yq) + name: yamlPathToImage + - description: The URL of the image to deploy + name: imageURL + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: '''the kind of job: postsubmit or presubmit''' + name: JOB_TYPE + type: string + - description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + - description: git url to clone + name: REPO_URL + type: string + spec: null + stepTemplate: + env: + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + name: "" + resources: {} + steps: + - args: + - w + - -i + - $(params.yqArg) + - $(params.path) + - $(params.yamlPathToImage) + - $(params.imageURL) + command: + - yq + image: mikefarah/yq + name: replace-image + resources: {} + - args: + - apply + - -f + - $(params.path) + command: + - kubectl + image: lachlanevenson/k8s-kubectl + name: run-kubectl + resources: {} + workspaces: + - name: source + workspaces: + - name: source + workspace: git-source + workspaces: + - name: git-source +status: {} diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-load-refs-sub-dir/kaniko.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-load-refs-sub-dir/kaniko.yaml new file mode 100644 index 0000000..07f2c51 --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-load-refs-sub-dir/kaniko.yaml @@ -0,0 +1,63 @@ +# Copied from https://github.com/tektoncd/catalog/blob/v1beta1/kaniko/kaniko.yaml +# with a few fixes that will be port over in https://github.com/tektoncd/catalog/pull/291 +# Post #1839 we can refer to the remote Task in a registry or post #2298 in git directly +apiVersion: tekton.dev/v1beta1 +kind: Task +metadata: + name: kaniko +spec: + workspaces: + - name: source + params: + - name: IMAGE + description: Name (reference) of the image to build. + - name: DOCKERFILE + description: Path to the Dockerfile to build. + default: ./Dockerfile + - name: CONTEXT + description: The build context used by Kaniko. + default: ./ + - name: EXTRA_ARGS + default: "" + - name: BUILDER_IMAGE + description: The image on which builds will run + default: gcr.io/kaniko-project/executor:latest + results: + - name: IMAGE_DIGEST + description: Digest of the image just built. + steps: + - name: build-and-push + workingDir: $(workspaces.source.path) + image: $(params.BUILDER_IMAGE) + # specifying DOCKER_CONFIG is required to allow kaniko to detect docker credential + # https://github.com/tektoncd/pipeline/pull/706 + env: + - name: DOCKER_CONFIG + value: /tekton/home/.docker + command: + - /kaniko/executor + - $(params.EXTRA_ARGS) + - --dockerfile=$(params.DOCKERFILE) + - --context=$(workspaces.source.path)/$(params.CONTEXT) # The user does not need to care the workspace and the source. + - --destination=$(params.IMAGE) + - --oci-layout-path=$(workspaces.source.path)/$(params.CONTEXT)/image-digest + # kaniko assumes it is running as root, which means this example fails on platforms + # that default to run containers as random uid (like OpenShift). Adding this securityContext + # makes it explicit that it needs to run as root. + securityContext: + runAsUser: 0 + - name: write-digest + workingDir: $(workspaces.source.path) + image: ko://github.com/tektoncd/pipeline/cmd/imagedigestexporter + # output of imagedigestexport [{"name":"image","digest":"sha256:eed29..660"}] + command: ["/ko-app/imagedigestexporter"] + securityContext: + runAsUser: 0 + args: + - -images=[{"name":"$(params.IMAGE)","type":"image","url":"$(params.IMAGE)","digest":"","OutputImageDir":"$(workspaces.source.path)/$(params.CONTEXT)/image-digest"}] + - -terminationMessagePath=$(params.CONTEXT)/image-digested + - name: digest-to-results + workingDir: $(workspaces.source.path) + image: stedolan/jq + script: | + cat $(params.CONTEXT)/image-digested | jq '.[0].value' -rj | tee /tekton/results/IMAGE_DIGEST \ No newline at end of file diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-load-refs-sub-dir/mydir/git-clone.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-load-refs-sub-dir/mydir/git-clone.yaml new file mode 100644 index 0000000..ab919a8 --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-load-refs-sub-dir/mydir/git-clone.yaml @@ -0,0 +1,80 @@ +# Copied from https://github.com/tektoncd/catalog/blob/v1beta1/git/git-clone.yaml +# With a few fixes being ported over in https://github.com/tektoncd/catalog/pull/290 +# Post #1839 we can refer to the remote Task in a registry or post #2298 in git directly +apiVersion: tekton.dev/v1beta1 +kind: Task +metadata: + name: git-clone +spec: + workspaces: + - name: output + description: The git repo will be cloned onto the volume backing this workspace + params: + - name: url + description: git url to clone + type: string + - name: revision + description: git revision to checkout (branch, tag, sha, ref…) + type: string + default: master + - name: submodules + description: defines if the resource should initialize and fetch the submodules + type: string + default: "true" + - name: depth + description: performs a shallow clone where only the most recent commit(s) will be fetched + type: string + default: "1" + - name: sslVerify + description: defines if http.sslVerify should be set to true or false in the global git config + type: string + default: "true" + - name: subdirectory + description: subdirectory inside the "output" workspace to clone the git repo into + type: string + default: "" + - name: deleteExisting + description: clean out the contents of the repo's destination directory (if it already exists) before trying to clone the repo there + type: string + default: "false" + results: + - name: commit + description: The precise commit SHA that was fetched by this Task + steps: + - name: clone + image: ko://github.com/tektoncd/pipeline/cmd/git-init + script: | + CHECKOUT_DIR="$(workspaces.output.path)/$(params.subdirectory)" + cleandir() { + # Delete any existing contents of the repo directory if it exists. + # + # We don't just "rm -rf $CHECKOUT_DIR" because $CHECKOUT_DIR might be "/" + # or the root of a mounted volume. + if [[ -d "$CHECKOUT_DIR" ]] ; then + # Delete non-hidden files and directories + rm -rf "$CHECKOUT_DIR"/* + # Delete files and directories starting with . but excluding .. + rm -rf "$CHECKOUT_DIR"/.[!.]* + # Delete files and directories starting with .. plus any other character + rm -rf "$CHECKOUT_DIR"/..?* + fi + } + if [[ "$(params.deleteExisting)" == "true" ]] ; then + cleandir + fi + /ko-app/git-init \ + -url "$(params.url)" \ + -revision "$(params.revision)" \ + -path "$CHECKOUT_DIR" \ + -sslVerify="$(params.sslVerify)" \ + -submodules="$(params.submodules)" \ + -depth="$(params.depth)" + cd "$CHECKOUT_DIR" + RESULT_SHA="$(git rev-parse HEAD | tr -d '\n')" + EXIT_CODE="$?" + if [ "$EXIT_CODE" != 0 ] + then + exit $EXIT_CODE + fi + # Make sure we don't add a trailing newline to the result! + echo -n "$RESULT_SHA" > $(results.commit.path) \ No newline at end of file diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-load-refs-sub-dir/source.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-load-refs-sub-dir/source.yaml new file mode 100644 index 0000000..9523d5d --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-load-refs-sub-dir/source.yaml @@ -0,0 +1,91 @@ +# This Pipeline Builds two microservice images(https://github.com/GoogleContainerTools/skaffold/tree/master/examples/microservices) +# from the Skaffold repo (https://github.com/GoogleContainerTools/skaffold) and deploys them to the repo currently running Tekton Pipelines. +apiVersion: tekton.dev/v1beta1 +kind: Pipeline +metadata: + name: demo-pipeline + annotations: + lighthouse.jenkins-x.io/loadFileRefs: ".*" +spec: + params: + - name: image-registry + default: gcr.io/christiewilson-catfactory + workspaces: + - name: git-source + tasks: + - name: fetch-from-git + taskRef: + name: mydir/git-clone + params: + - name: url + value: https://github.com/GoogleContainerTools/skaffold + - name: revision + value: v0.32.0 + workspaces: + - name: output + workspace: git-source + - name: skaffold-unit-tests + runAfter: [fetch-from-git] + taskRef: + name: unit-tests + workspaces: + - name: source + workspace: git-source + - name: build-skaffold-web + runAfter: [skaffold-unit-tests] + taskRef: + name: kaniko + params: + - name: IMAGE + value: $(params.image-registry)/leeroy-web + - name: CONTEXT + value: examples/microservices/leeroy-web + - name: DOCKERFILE + value: $(workspaces.source.path)/examples/microservices/leeroy-web/Dockerfile + workspaces: + - name: source + workspace: git-source + - name: build-skaffold-app + runAfter: [skaffold-unit-tests] + taskRef: + name: kaniko + params: + - name: IMAGE + value: $(params.image-registry)/leeroy-app + - name: CONTEXT + value: examples/microservices/leeroy-app + - name: DOCKERFILE + value: $(workspaces.source.path)/examples/microservices/leeroy-app/Dockerfile + workspaces: + - name: source + workspace: git-source + - name: deploy-app + taskRef: + name: demo-deploy-kubectl + params: + - name: imageURL + value: $(params.image-registry)/leeroy-app@$(tasks.build-skaffold-app.results.IMAGE_DIGEST) + - name: path + value: $(workspaces.source.path)/examples/microservices/leeroy-app/kubernetes/deployment.yaml + - name: yqArg + value: "-d1" + - name: yamlPathToImage + value: "spec.template.spec.containers[0].image" + workspaces: + - name: source + workspace: git-source + - name: deploy-web + taskRef: + name: demo-deploy-kubectl + params: + - name: imageURL + value: $(params.image-registry)/leeroy-web@$(tasks.build-skaffold-web.results.IMAGE_DIGEST) + - name: path + value: $(workspaces.source.path)/examples/microservices/leeroy-web/kubernetes/deployment.yaml + - name: yqArg + value: "-d1" + - name: yamlPathToImage + value: "spec.template.spec.containers[0].image" + workspaces: + - name: source + workspace: git-source \ No newline at end of file diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-load-refs-sub-dir/unit-tests.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-load-refs-sub-dir/unit-tests.yaml new file mode 100644 index 0000000..f69fc77 --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-load-refs-sub-dir/unit-tests.yaml @@ -0,0 +1,21 @@ +apiVersion: tekton.dev/v1beta1 +kind: Task +metadata: + name: unit-tests +spec: + workspaces: + - name: source + mountPath: /workspace/source/go/src/github.com/GoogleContainerTools/skaffold + steps: + - name: run-tests + image: golang + env: + - name: GOPATH + value: /workspace/go + workingDir: $(workspaces.source.path) + script: | + # The intention behind this example Task is to run unit test, however we + # currently do nothing to ensure that a unit test issue doesn't cause this example + # to fail unnecessarily. In the future we could re-introduce the unit tests (since + # we are now pinning the version of Skaffold we pull) or use Tekton Pipelines unit tests. + echo "pass" \ No newline at end of file diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-load-refs/demo-deploy-kubectl.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-load-refs/demo-deploy-kubectl.yaml new file mode 100644 index 0000000..16085bb --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-load-refs/demo-deploy-kubectl.yaml @@ -0,0 +1,35 @@ +# This task deploys with kubectl apply -f +apiVersion: tekton.dev/v1beta1 +kind: Task +metadata: + name: demo-deploy-kubectl +spec: + params: + - name: path + description: Path to the manifest to apply + - name: yqArg + description: Okay this is a hack, but I didn't feel right hard-coding `-d1` down below + - name: yamlPathToImage + description: The path to the image to replace in the yaml manifest (arg to yq) + - name: imageURL + description: The URL of the image to deploy + workspaces: + - name: source + steps: + - name: replace-image + image: mikefarah/yq + command: ['yq'] + args: + - "w" + - "-i" + - "$(params.yqArg)" + - "$(params.path)" + - "$(params.yamlPathToImage)" + - "$(params.imageURL)" + - name: run-kubectl + image: lachlanevenson/k8s-kubectl + command: ['kubectl'] + args: + - 'apply' + - '-f' + - '$(params.path)' \ No newline at end of file diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-load-refs/expected.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-load-refs/expected.yaml new file mode 100644 index 0000000..501e7eb --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-load-refs/expected.yaml @@ -0,0 +1,1003 @@ +apiVersion: tekton.dev/v1beta1 +kind: PipelineRun +metadata: + annotations: + lighthouse.jenkins-x.io/loadFileRefs: .* + creationTimestamp: null + name: demo-pipeline +spec: + pipelineSpec: + params: + - default: gcr.io/christiewilson-catfactory + name: image-registry + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: '''the kind of job: postsubmit or presubmit''' + name: JOB_TYPE + type: string + - description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + - description: git url to clone + name: REPO_URL + type: string + tasks: + - name: fetch-from-git + params: + - name: url + value: https://github.com/GoogleContainerTools/skaffold + - name: revision + value: v0.32.0 + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + taskSpec: + metadata: {} + params: + - description: git url to clone + name: url + type: string + - default: master + description: git revision to checkout (branch, tag, sha, ref…) + name: revision + type: string + - default: "true" + description: defines if the resource should initialize and fetch the submodules + name: submodules + type: string + - default: "1" + description: performs a shallow clone where only the most recent commit(s) + will be fetched + name: depth + type: string + - default: "true" + description: defines if http.sslVerify should be set to true or false in + the global git config + name: sslVerify + type: string + - default: "" + description: subdirectory inside the "output" workspace to clone the git + repo into + name: subdirectory + type: string + - default: "false" + description: clean out the contents of the repo's destination directory + (if it already exists) before trying to clone the repo there + name: deleteExisting + type: string + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: '''the kind of job: postsubmit or presubmit''' + name: JOB_TYPE + type: string + - description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + - description: git url to clone + name: REPO_URL + type: string + results: + - description: The precise commit SHA that was fetched by this Task + name: commit + spec: null + stepTemplate: + env: + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + name: "" + resources: {} + steps: + - image: ko://github.com/tektoncd/pipeline/cmd/git-init + name: clone + resources: {} + script: |- + CHECKOUT_DIR="$(workspaces.output.path)/$(params.subdirectory)" + cleandir() { + # Delete any existing contents of the repo directory if it exists. + # + # We don't just "rm -rf $CHECKOUT_DIR" because $CHECKOUT_DIR might be "/" + # or the root of a mounted volume. + if [[ -d "$CHECKOUT_DIR" ]] ; then + # Delete non-hidden files and directories + rm -rf "$CHECKOUT_DIR"/* + # Delete files and directories starting with . but excluding .. + rm -rf "$CHECKOUT_DIR"/.[!.]* + # Delete files and directories starting with .. plus any other character + rm -rf "$CHECKOUT_DIR"/..?* + fi + } + if [[ "$(params.deleteExisting)" == "true" ]] ; then + cleandir + fi + /ko-app/git-init \ + -url "$(params.url)" \ + -revision "$(params.revision)" \ + -path "$CHECKOUT_DIR" \ + -sslVerify="$(params.sslVerify)" \ + -submodules="$(params.submodules)" \ + -depth="$(params.depth)" + cd "$CHECKOUT_DIR" + RESULT_SHA="$(git rev-parse HEAD | tr -d '\n')" + EXIT_CODE="$?" + if [ "$EXIT_CODE" != 0 ] + then + exit $EXIT_CODE + fi + # Make sure we don't add a trailing newline to the result! + echo -n "$RESULT_SHA" > $(results.commit.path) + workspaces: + - description: The git repo will be cloned onto the volume backing this workspace + name: output + workspaces: + - name: output + workspace: git-source + - name: skaffold-unit-tests + params: + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + runAfter: + - fetch-from-git + taskSpec: + metadata: {} + params: + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: '''the kind of job: postsubmit or presubmit''' + name: JOB_TYPE + type: string + - description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + - description: git url to clone + name: REPO_URL + type: string + spec: null + stepTemplate: + env: + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + name: "" + resources: {} + steps: + - env: + - name: GOPATH + value: /workspace/go + image: golang + name: run-tests + resources: {} + script: |- + # The intention behind this example Task is to run unit test, however we + # currently do nothing to ensure that a unit test issue doesn't cause this example + # to fail unnecessarily. In the future we could re-introduce the unit tests (since + # we are now pinning the version of Skaffold we pull) or use Tekton Pipelines unit tests. + echo "pass" + workingDir: $(workspaces.source.path) + workspaces: + - mountPath: /workspace/source/go/src/github.com/GoogleContainerTools/skaffold + name: source + workspaces: + - name: source + workspace: git-source + - name: build-skaffold-web + params: + - name: IMAGE + value: $(params.image-registry)/leeroy-web + - name: CONTEXT + value: examples/microservices/leeroy-web + - name: DOCKERFILE + value: $(workspaces.source.path)/examples/microservices/leeroy-web/Dockerfile + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + runAfter: + - skaffold-unit-tests + taskSpec: + metadata: {} + params: + - description: Name (reference) of the image to build. + name: IMAGE + - default: ./Dockerfile + description: Path to the Dockerfile to build. + name: DOCKERFILE + - default: ./ + description: The build context used by Kaniko. + name: CONTEXT + - default: "" + name: EXTRA_ARGS + - default: gcr.io/kaniko-project/executor:latest + description: The image on which builds will run + name: BUILDER_IMAGE + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: '''the kind of job: postsubmit or presubmit''' + name: JOB_TYPE + type: string + - description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + - description: git url to clone + name: REPO_URL + type: string + results: + - description: Digest of the image just built. + name: IMAGE_DIGEST + spec: null + stepTemplate: + env: + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + name: "" + resources: {} + steps: + - command: + - /kaniko/executor + - $(params.EXTRA_ARGS) + - --dockerfile=$(params.DOCKERFILE) + - --context=$(workspaces.source.path)/$(params.CONTEXT) + - --destination=$(params.IMAGE) + - --oci-layout-path=$(workspaces.source.path)/$(params.CONTEXT)/image-digest + env: + - name: DOCKER_CONFIG + value: /tekton/home/.docker + image: $(params.BUILDER_IMAGE) + name: build-and-push + resources: {} + securityContext: + runAsUser: 0 + workingDir: $(workspaces.source.path) + - args: + - -images=[{"name":"$(params.IMAGE)","type":"image","url":"$(params.IMAGE)","digest":"","OutputImageDir":"$(workspaces.source.path)/$(params.CONTEXT)/image-digest"}] + - -terminationMessagePath=$(params.CONTEXT)/image-digested + command: + - /ko-app/imagedigestexporter + image: ko://github.com/tektoncd/pipeline/cmd/imagedigestexporter + name: write-digest + resources: {} + securityContext: + runAsUser: 0 + workingDir: $(workspaces.source.path) + - image: stedolan/jq + name: digest-to-results + resources: {} + script: cat $(params.CONTEXT)/image-digested | jq '.[0].value' -rj | tee + /tekton/results/IMAGE_DIGEST + workingDir: $(workspaces.source.path) + workspaces: + - name: source + workspaces: + - name: source + workspace: git-source + - name: build-skaffold-app + params: + - name: IMAGE + value: $(params.image-registry)/leeroy-app + - name: CONTEXT + value: examples/microservices/leeroy-app + - name: DOCKERFILE + value: $(workspaces.source.path)/examples/microservices/leeroy-app/Dockerfile + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + runAfter: + - skaffold-unit-tests + taskSpec: + metadata: {} + params: + - description: Name (reference) of the image to build. + name: IMAGE + - default: ./Dockerfile + description: Path to the Dockerfile to build. + name: DOCKERFILE + - default: ./ + description: The build context used by Kaniko. + name: CONTEXT + - default: "" + name: EXTRA_ARGS + - default: gcr.io/kaniko-project/executor:latest + description: The image on which builds will run + name: BUILDER_IMAGE + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: '''the kind of job: postsubmit or presubmit''' + name: JOB_TYPE + type: string + - description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + - description: git url to clone + name: REPO_URL + type: string + results: + - description: Digest of the image just built. + name: IMAGE_DIGEST + spec: null + stepTemplate: + env: + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + name: "" + resources: {} + steps: + - command: + - /kaniko/executor + - $(params.EXTRA_ARGS) + - --dockerfile=$(params.DOCKERFILE) + - --context=$(workspaces.source.path)/$(params.CONTEXT) + - --destination=$(params.IMAGE) + - --oci-layout-path=$(workspaces.source.path)/$(params.CONTEXT)/image-digest + env: + - name: DOCKER_CONFIG + value: /tekton/home/.docker + image: $(params.BUILDER_IMAGE) + name: build-and-push + resources: {} + securityContext: + runAsUser: 0 + workingDir: $(workspaces.source.path) + - args: + - -images=[{"name":"$(params.IMAGE)","type":"image","url":"$(params.IMAGE)","digest":"","OutputImageDir":"$(workspaces.source.path)/$(params.CONTEXT)/image-digest"}] + - -terminationMessagePath=$(params.CONTEXT)/image-digested + command: + - /ko-app/imagedigestexporter + image: ko://github.com/tektoncd/pipeline/cmd/imagedigestexporter + name: write-digest + resources: {} + securityContext: + runAsUser: 0 + workingDir: $(workspaces.source.path) + - image: stedolan/jq + name: digest-to-results + resources: {} + script: cat $(params.CONTEXT)/image-digested | jq '.[0].value' -rj | tee + /tekton/results/IMAGE_DIGEST + workingDir: $(workspaces.source.path) + workspaces: + - name: source + workspaces: + - name: source + workspace: git-source + - name: deploy-app + params: + - name: imageURL + value: $(params.image-registry)/leeroy-app@$(tasks.build-skaffold-app.results.IMAGE_DIGEST) + - name: path + value: $(workspaces.source.path)/examples/microservices/leeroy-app/kubernetes/deployment.yaml + - name: yqArg + value: -d1 + - name: yamlPathToImage + value: spec.template.spec.containers[0].image + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + taskSpec: + metadata: {} + params: + - description: Path to the manifest to apply + name: path + - description: Okay this is a hack, but I didn't feel right hard-coding `-d1` + down below + name: yqArg + - description: The path to the image to replace in the yaml manifest (arg + to yq) + name: yamlPathToImage + - description: The URL of the image to deploy + name: imageURL + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: '''the kind of job: postsubmit or presubmit''' + name: JOB_TYPE + type: string + - description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + - description: git url to clone + name: REPO_URL + type: string + spec: null + stepTemplate: + env: + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + name: "" + resources: {} + steps: + - args: + - w + - -i + - $(params.yqArg) + - $(params.path) + - $(params.yamlPathToImage) + - $(params.imageURL) + command: + - yq + image: mikefarah/yq + name: replace-image + resources: {} + - args: + - apply + - -f + - $(params.path) + command: + - kubectl + image: lachlanevenson/k8s-kubectl + name: run-kubectl + resources: {} + workspaces: + - name: source + workspaces: + - name: source + workspace: git-source + - name: deploy-web + params: + - name: imageURL + value: $(params.image-registry)/leeroy-web@$(tasks.build-skaffold-web.results.IMAGE_DIGEST) + - name: path + value: $(workspaces.source.path)/examples/microservices/leeroy-web/kubernetes/deployment.yaml + - name: yqArg + value: -d1 + - name: yamlPathToImage + value: spec.template.spec.containers[0].image + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + taskSpec: + metadata: {} + params: + - description: Path to the manifest to apply + name: path + - description: Okay this is a hack, but I didn't feel right hard-coding `-d1` + down below + name: yqArg + - description: The path to the image to replace in the yaml manifest (arg + to yq) + name: yamlPathToImage + - description: The URL of the image to deploy + name: imageURL + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: '''the kind of job: postsubmit or presubmit''' + name: JOB_TYPE + type: string + - description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + - description: git url to clone + name: REPO_URL + type: string + spec: null + stepTemplate: + env: + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + name: "" + resources: {} + steps: + - args: + - w + - -i + - $(params.yqArg) + - $(params.path) + - $(params.yamlPathToImage) + - $(params.imageURL) + command: + - yq + image: mikefarah/yq + name: replace-image + resources: {} + - args: + - apply + - -f + - $(params.path) + command: + - kubectl + image: lachlanevenson/k8s-kubectl + name: run-kubectl + resources: {} + workspaces: + - name: source + workspaces: + - name: source + workspace: git-source + workspaces: + - name: git-source +status: {} diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-load-refs/git-clone.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-load-refs/git-clone.yaml new file mode 100644 index 0000000..ab919a8 --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-load-refs/git-clone.yaml @@ -0,0 +1,80 @@ +# Copied from https://github.com/tektoncd/catalog/blob/v1beta1/git/git-clone.yaml +# With a few fixes being ported over in https://github.com/tektoncd/catalog/pull/290 +# Post #1839 we can refer to the remote Task in a registry or post #2298 in git directly +apiVersion: tekton.dev/v1beta1 +kind: Task +metadata: + name: git-clone +spec: + workspaces: + - name: output + description: The git repo will be cloned onto the volume backing this workspace + params: + - name: url + description: git url to clone + type: string + - name: revision + description: git revision to checkout (branch, tag, sha, ref…) + type: string + default: master + - name: submodules + description: defines if the resource should initialize and fetch the submodules + type: string + default: "true" + - name: depth + description: performs a shallow clone where only the most recent commit(s) will be fetched + type: string + default: "1" + - name: sslVerify + description: defines if http.sslVerify should be set to true or false in the global git config + type: string + default: "true" + - name: subdirectory + description: subdirectory inside the "output" workspace to clone the git repo into + type: string + default: "" + - name: deleteExisting + description: clean out the contents of the repo's destination directory (if it already exists) before trying to clone the repo there + type: string + default: "false" + results: + - name: commit + description: The precise commit SHA that was fetched by this Task + steps: + - name: clone + image: ko://github.com/tektoncd/pipeline/cmd/git-init + script: | + CHECKOUT_DIR="$(workspaces.output.path)/$(params.subdirectory)" + cleandir() { + # Delete any existing contents of the repo directory if it exists. + # + # We don't just "rm -rf $CHECKOUT_DIR" because $CHECKOUT_DIR might be "/" + # or the root of a mounted volume. + if [[ -d "$CHECKOUT_DIR" ]] ; then + # Delete non-hidden files and directories + rm -rf "$CHECKOUT_DIR"/* + # Delete files and directories starting with . but excluding .. + rm -rf "$CHECKOUT_DIR"/.[!.]* + # Delete files and directories starting with .. plus any other character + rm -rf "$CHECKOUT_DIR"/..?* + fi + } + if [[ "$(params.deleteExisting)" == "true" ]] ; then + cleandir + fi + /ko-app/git-init \ + -url "$(params.url)" \ + -revision "$(params.revision)" \ + -path "$CHECKOUT_DIR" \ + -sslVerify="$(params.sslVerify)" \ + -submodules="$(params.submodules)" \ + -depth="$(params.depth)" + cd "$CHECKOUT_DIR" + RESULT_SHA="$(git rev-parse HEAD | tr -d '\n')" + EXIT_CODE="$?" + if [ "$EXIT_CODE" != 0 ] + then + exit $EXIT_CODE + fi + # Make sure we don't add a trailing newline to the result! + echo -n "$RESULT_SHA" > $(results.commit.path) \ No newline at end of file diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-load-refs/kaniko.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-load-refs/kaniko.yaml new file mode 100644 index 0000000..07f2c51 --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-load-refs/kaniko.yaml @@ -0,0 +1,63 @@ +# Copied from https://github.com/tektoncd/catalog/blob/v1beta1/kaniko/kaniko.yaml +# with a few fixes that will be port over in https://github.com/tektoncd/catalog/pull/291 +# Post #1839 we can refer to the remote Task in a registry or post #2298 in git directly +apiVersion: tekton.dev/v1beta1 +kind: Task +metadata: + name: kaniko +spec: + workspaces: + - name: source + params: + - name: IMAGE + description: Name (reference) of the image to build. + - name: DOCKERFILE + description: Path to the Dockerfile to build. + default: ./Dockerfile + - name: CONTEXT + description: The build context used by Kaniko. + default: ./ + - name: EXTRA_ARGS + default: "" + - name: BUILDER_IMAGE + description: The image on which builds will run + default: gcr.io/kaniko-project/executor:latest + results: + - name: IMAGE_DIGEST + description: Digest of the image just built. + steps: + - name: build-and-push + workingDir: $(workspaces.source.path) + image: $(params.BUILDER_IMAGE) + # specifying DOCKER_CONFIG is required to allow kaniko to detect docker credential + # https://github.com/tektoncd/pipeline/pull/706 + env: + - name: DOCKER_CONFIG + value: /tekton/home/.docker + command: + - /kaniko/executor + - $(params.EXTRA_ARGS) + - --dockerfile=$(params.DOCKERFILE) + - --context=$(workspaces.source.path)/$(params.CONTEXT) # The user does not need to care the workspace and the source. + - --destination=$(params.IMAGE) + - --oci-layout-path=$(workspaces.source.path)/$(params.CONTEXT)/image-digest + # kaniko assumes it is running as root, which means this example fails on platforms + # that default to run containers as random uid (like OpenShift). Adding this securityContext + # makes it explicit that it needs to run as root. + securityContext: + runAsUser: 0 + - name: write-digest + workingDir: $(workspaces.source.path) + image: ko://github.com/tektoncd/pipeline/cmd/imagedigestexporter + # output of imagedigestexport [{"name":"image","digest":"sha256:eed29..660"}] + command: ["/ko-app/imagedigestexporter"] + securityContext: + runAsUser: 0 + args: + - -images=[{"name":"$(params.IMAGE)","type":"image","url":"$(params.IMAGE)","digest":"","OutputImageDir":"$(workspaces.source.path)/$(params.CONTEXT)/image-digest"}] + - -terminationMessagePath=$(params.CONTEXT)/image-digested + - name: digest-to-results + workingDir: $(workspaces.source.path) + image: stedolan/jq + script: | + cat $(params.CONTEXT)/image-digested | jq '.[0].value' -rj | tee /tekton/results/IMAGE_DIGEST \ No newline at end of file diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-load-refs/source.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-load-refs/source.yaml new file mode 100644 index 0000000..783552f --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-load-refs/source.yaml @@ -0,0 +1,91 @@ +# This Pipeline Builds two microservice images(https://github.com/GoogleContainerTools/skaffold/tree/master/examples/microservices) +# from the Skaffold repo (https://github.com/GoogleContainerTools/skaffold) and deploys them to the repo currently running Tekton Pipelines. +apiVersion: tekton.dev/v1beta1 +kind: Pipeline +metadata: + name: demo-pipeline + annotations: + lighthouse.jenkins-x.io/loadFileRefs: ".*" +spec: + params: + - name: image-registry + default: gcr.io/christiewilson-catfactory + workspaces: + - name: git-source + tasks: + - name: fetch-from-git + taskRef: + name: git-clone + params: + - name: url + value: https://github.com/GoogleContainerTools/skaffold + - name: revision + value: v0.32.0 + workspaces: + - name: output + workspace: git-source + - name: skaffold-unit-tests + runAfter: [fetch-from-git] + taskRef: + name: unit-tests + workspaces: + - name: source + workspace: git-source + - name: build-skaffold-web + runAfter: [skaffold-unit-tests] + taskRef: + name: kaniko + params: + - name: IMAGE + value: $(params.image-registry)/leeroy-web + - name: CONTEXT + value: examples/microservices/leeroy-web + - name: DOCKERFILE + value: $(workspaces.source.path)/examples/microservices/leeroy-web/Dockerfile + workspaces: + - name: source + workspace: git-source + - name: build-skaffold-app + runAfter: [skaffold-unit-tests] + taskRef: + name: kaniko + params: + - name: IMAGE + value: $(params.image-registry)/leeroy-app + - name: CONTEXT + value: examples/microservices/leeroy-app + - name: DOCKERFILE + value: $(workspaces.source.path)/examples/microservices/leeroy-app/Dockerfile + workspaces: + - name: source + workspace: git-source + - name: deploy-app + taskRef: + name: demo-deploy-kubectl + params: + - name: imageURL + value: $(params.image-registry)/leeroy-app@$(tasks.build-skaffold-app.results.IMAGE_DIGEST) + - name: path + value: $(workspaces.source.path)/examples/microservices/leeroy-app/kubernetes/deployment.yaml + - name: yqArg + value: "-d1" + - name: yamlPathToImage + value: "spec.template.spec.containers[0].image" + workspaces: + - name: source + workspace: git-source + - name: deploy-web + taskRef: + name: demo-deploy-kubectl + params: + - name: imageURL + value: $(params.image-registry)/leeroy-web@$(tasks.build-skaffold-web.results.IMAGE_DIGEST) + - name: path + value: $(workspaces.source.path)/examples/microservices/leeroy-web/kubernetes/deployment.yaml + - name: yqArg + value: "-d1" + - name: yamlPathToImage + value: "spec.template.spec.containers[0].image" + workspaces: + - name: source + workspace: git-source \ No newline at end of file diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-load-refs/unit-tests.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-load-refs/unit-tests.yaml new file mode 100644 index 0000000..f69fc77 --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-load-refs/unit-tests.yaml @@ -0,0 +1,21 @@ +apiVersion: tekton.dev/v1beta1 +kind: Task +metadata: + name: unit-tests +spec: + workspaces: + - name: source + mountPath: /workspace/source/go/src/github.com/GoogleContainerTools/skaffold + steps: + - name: run-tests + image: golang + env: + - name: GOPATH + value: /workspace/go + workingDir: $(workspaces.source.path) + script: | + # The intention behind this example Task is to run unit test, however we + # currently do nothing to ensure that a unit test issue doesn't cause this example + # to fail unnecessarily. In the future we could re-introduce the unit tests (since + # we are now pinning the version of Skaffold we pull) or use Tekton Pipelines unit tests. + echo "pass" \ No newline at end of file diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-missing-refs-fails/source.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-missing-refs-fails/source.yaml new file mode 100644 index 0000000..783552f --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-missing-refs-fails/source.yaml @@ -0,0 +1,91 @@ +# This Pipeline Builds two microservice images(https://github.com/GoogleContainerTools/skaffold/tree/master/examples/microservices) +# from the Skaffold repo (https://github.com/GoogleContainerTools/skaffold) and deploys them to the repo currently running Tekton Pipelines. +apiVersion: tekton.dev/v1beta1 +kind: Pipeline +metadata: + name: demo-pipeline + annotations: + lighthouse.jenkins-x.io/loadFileRefs: ".*" +spec: + params: + - name: image-registry + default: gcr.io/christiewilson-catfactory + workspaces: + - name: git-source + tasks: + - name: fetch-from-git + taskRef: + name: git-clone + params: + - name: url + value: https://github.com/GoogleContainerTools/skaffold + - name: revision + value: v0.32.0 + workspaces: + - name: output + workspace: git-source + - name: skaffold-unit-tests + runAfter: [fetch-from-git] + taskRef: + name: unit-tests + workspaces: + - name: source + workspace: git-source + - name: build-skaffold-web + runAfter: [skaffold-unit-tests] + taskRef: + name: kaniko + params: + - name: IMAGE + value: $(params.image-registry)/leeroy-web + - name: CONTEXT + value: examples/microservices/leeroy-web + - name: DOCKERFILE + value: $(workspaces.source.path)/examples/microservices/leeroy-web/Dockerfile + workspaces: + - name: source + workspace: git-source + - name: build-skaffold-app + runAfter: [skaffold-unit-tests] + taskRef: + name: kaniko + params: + - name: IMAGE + value: $(params.image-registry)/leeroy-app + - name: CONTEXT + value: examples/microservices/leeroy-app + - name: DOCKERFILE + value: $(workspaces.source.path)/examples/microservices/leeroy-app/Dockerfile + workspaces: + - name: source + workspace: git-source + - name: deploy-app + taskRef: + name: demo-deploy-kubectl + params: + - name: imageURL + value: $(params.image-registry)/leeroy-app@$(tasks.build-skaffold-app.results.IMAGE_DIGEST) + - name: path + value: $(workspaces.source.path)/examples/microservices/leeroy-app/kubernetes/deployment.yaml + - name: yqArg + value: "-d1" + - name: yamlPathToImage + value: "spec.template.spec.containers[0].image" + workspaces: + - name: source + workspace: git-source + - name: deploy-web + taskRef: + name: demo-deploy-kubectl + params: + - name: imageURL + value: $(params.image-registry)/leeroy-web@$(tasks.build-skaffold-web.results.IMAGE_DIGEST) + - name: path + value: $(workspaces.source.path)/examples/microservices/leeroy-web/kubernetes/deployment.yaml + - name: yqArg + value: "-d1" + - name: yamlPathToImage + value: "spec.template.spec.containers[0].image" + workspaces: + - name: source + workspace: git-source \ No newline at end of file diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-tekton-git-resolver/expected.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-tekton-git-resolver/expected.yaml new file mode 100644 index 0000000..a570429 --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-tekton-git-resolver/expected.yaml @@ -0,0 +1,192 @@ +apiVersion: tekton.dev/v1beta1 +kind: PipelineRun +metadata: + creationTimestamp: null + name: pullrequest +spec: + pipelineSpec: + params: + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: '''the kind of job: postsubmit or presubmit''' + name: JOB_TYPE + type: string + - description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + - description: git url to clone + name: REPO_URL + type: string + tasks: + - name: git-clone-env-pr + params: + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + taskRef: + params: + - name: url + value: https://github.com/jenkins-x/jx3-pipeline-catalog.git + - name: revision + value: master + - name: pathInRepo + value: tasks/git-clone/git-clone-env-pr.yaml + resolver: git + workspaces: + - name: output + workspace: pipeline-ws + - name: make-pr + params: + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + runAfter: + - git-clone-env-pr + taskRef: + params: + - name: url + value: https://github.com/jenkins-x/jx3-pipeline-catalog.git + - name: revision + value: master + - name: pathInRepo + value: tasks/environment/pullrequest/make-pr.yaml + resolver: git + workspaces: + - name: output + workspace: pipeline-ws + - name: kubetest + params: + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + runAfter: + - make-pr + taskRef: + params: + - name: url + value: https://github.com/jenkins-x/jx3-pipeline-catalog.git + - name: revision + value: master + - name: pathInRepo + value: tasks/kubetest/environment.yaml + resolver: git + workspaces: + - name: output + workspace: pipeline-ws + workspaces: + - name: pipeline-ws + serviceAccountName: tekton-bot + timeout: 12h0m0s + workspaces: + - name: pipeline-ws + volumeClaimTemplate: + metadata: + creationTimestamp: null + spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 1Gi + status: {} +status: {} diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-tekton-git-resolver/source.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-tekton-git-resolver/source.yaml new file mode 100644 index 0000000..95273d0 --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline-tekton-git-resolver/source.yaml @@ -0,0 +1,68 @@ +apiVersion: tekton.dev/v1beta1 +kind: PipelineRun +metadata: + creationTimestamp: null + name: pullrequest +spec: + pipelineSpec: + tasks: + - name: git-clone-env-pr + taskRef: + params: + - name: url + value: https://github.com/jenkins-x/jx3-pipeline-catalog.git + - name: revision + value: master + - name: pathInRepo + value: tasks/git-clone/git-clone-env-pr.yaml + resolver: git + workspaces: + - name: output + workspace: pipeline-ws + - name: make-pr + runAfter: + - git-clone-env-pr + taskRef: + params: + - name: url + value: https://github.com/jenkins-x/jx3-pipeline-catalog.git + - name: revision + value: master + - name: pathInRepo + value: tasks/environment/pullrequest/make-pr.yaml + resolver: git + workspaces: + - name: output + workspace: pipeline-ws + - name: kubetest + runAfter: + - make-pr + taskRef: + params: + - name: url + value: https://github.com/jenkins-x/jx3-pipeline-catalog.git + - name: revision + value: master + - name: pathInRepo + value: tasks/kubetest/environment.yaml + resolver: git + workspaces: + - name: output + workspace: pipeline-ws + workspaces: + - name: pipeline-ws + serviceAccountName: tekton-bot + timeout: 12h0m0s + workspaces: + - name: pipeline-ws + volumeClaimTemplate: + metadata: + creationTimestamp: null + spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 1Gi + status: {} +status: {} diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline/demo-deploy-kubectl.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline/demo-deploy-kubectl.yaml new file mode 100644 index 0000000..16085bb --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline/demo-deploy-kubectl.yaml @@ -0,0 +1,35 @@ +# This task deploys with kubectl apply -f +apiVersion: tekton.dev/v1beta1 +kind: Task +metadata: + name: demo-deploy-kubectl +spec: + params: + - name: path + description: Path to the manifest to apply + - name: yqArg + description: Okay this is a hack, but I didn't feel right hard-coding `-d1` down below + - name: yamlPathToImage + description: The path to the image to replace in the yaml manifest (arg to yq) + - name: imageURL + description: The URL of the image to deploy + workspaces: + - name: source + steps: + - name: replace-image + image: mikefarah/yq + command: ['yq'] + args: + - "w" + - "-i" + - "$(params.yqArg)" + - "$(params.path)" + - "$(params.yamlPathToImage)" + - "$(params.imageURL)" + - name: run-kubectl + image: lachlanevenson/k8s-kubectl + command: ['kubectl'] + args: + - 'apply' + - '-f' + - '$(params.path)' \ No newline at end of file diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline/expected.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline/expected.yaml new file mode 100644 index 0000000..16fcf50 --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline/expected.yaml @@ -0,0 +1,292 @@ +apiVersion: tekton.dev/v1beta1 +kind: PipelineRun +metadata: + creationTimestamp: null + name: demo-pipeline +spec: + pipelineSpec: + params: + - default: gcr.io/christiewilson-catfactory + name: image-registry + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: '''the kind of job: postsubmit or presubmit''' + name: JOB_TYPE + type: string + - description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + - description: git url to clone + name: REPO_URL + type: string + tasks: + - name: fetch-from-git + params: + - name: url + value: https://github.com/GoogleContainerTools/skaffold + - name: revision + value: v0.32.0 + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + taskRef: + name: git-clone + workspaces: + - name: output + workspace: git-source + - name: skaffold-unit-tests + params: + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + runAfter: + - fetch-from-git + taskRef: + name: unit-tests + workspaces: + - name: source + workspace: git-source + - name: build-skaffold-web + params: + - name: IMAGE + value: $(params.image-registry)/leeroy-web + - name: CONTEXT + value: examples/microservices/leeroy-web + - name: DOCKERFILE + value: $(workspaces.source.path)/examples/microservices/leeroy-web/Dockerfile + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + runAfter: + - skaffold-unit-tests + taskRef: + name: kaniko + workspaces: + - name: source + workspace: git-source + - name: build-skaffold-app + params: + - name: IMAGE + value: $(params.image-registry)/leeroy-app + - name: CONTEXT + value: examples/microservices/leeroy-app + - name: DOCKERFILE + value: $(workspaces.source.path)/examples/microservices/leeroy-app/Dockerfile + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + runAfter: + - skaffold-unit-tests + taskRef: + name: kaniko + workspaces: + - name: source + workspace: git-source + - name: deploy-app + params: + - name: imageURL + value: $(params.image-registry)/leeroy-app@$(tasks.build-skaffold-app.results.IMAGE_DIGEST) + - name: path + value: $(workspaces.source.path)/examples/microservices/leeroy-app/kubernetes/deployment.yaml + - name: yqArg + value: -d1 + - name: yamlPathToImage + value: spec.template.spec.containers[0].image + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + taskRef: + name: demo-deploy-kubectl + workspaces: + - name: source + workspace: git-source + - name: deploy-web + params: + - name: imageURL + value: $(params.image-registry)/leeroy-web@$(tasks.build-skaffold-web.results.IMAGE_DIGEST) + - name: path + value: $(workspaces.source.path)/examples/microservices/leeroy-web/kubernetes/deployment.yaml + - name: yqArg + value: -d1 + - name: yamlPathToImage + value: spec.template.spec.containers[0].image + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + taskRef: + name: demo-deploy-kubectl + workspaces: + - name: source + workspace: git-source + workspaces: + - name: git-source +status: {} diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline/git-clone.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline/git-clone.yaml new file mode 100644 index 0000000..ab919a8 --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline/git-clone.yaml @@ -0,0 +1,80 @@ +# Copied from https://github.com/tektoncd/catalog/blob/v1beta1/git/git-clone.yaml +# With a few fixes being ported over in https://github.com/tektoncd/catalog/pull/290 +# Post #1839 we can refer to the remote Task in a registry or post #2298 in git directly +apiVersion: tekton.dev/v1beta1 +kind: Task +metadata: + name: git-clone +spec: + workspaces: + - name: output + description: The git repo will be cloned onto the volume backing this workspace + params: + - name: url + description: git url to clone + type: string + - name: revision + description: git revision to checkout (branch, tag, sha, ref…) + type: string + default: master + - name: submodules + description: defines if the resource should initialize and fetch the submodules + type: string + default: "true" + - name: depth + description: performs a shallow clone where only the most recent commit(s) will be fetched + type: string + default: "1" + - name: sslVerify + description: defines if http.sslVerify should be set to true or false in the global git config + type: string + default: "true" + - name: subdirectory + description: subdirectory inside the "output" workspace to clone the git repo into + type: string + default: "" + - name: deleteExisting + description: clean out the contents of the repo's destination directory (if it already exists) before trying to clone the repo there + type: string + default: "false" + results: + - name: commit + description: The precise commit SHA that was fetched by this Task + steps: + - name: clone + image: ko://github.com/tektoncd/pipeline/cmd/git-init + script: | + CHECKOUT_DIR="$(workspaces.output.path)/$(params.subdirectory)" + cleandir() { + # Delete any existing contents of the repo directory if it exists. + # + # We don't just "rm -rf $CHECKOUT_DIR" because $CHECKOUT_DIR might be "/" + # or the root of a mounted volume. + if [[ -d "$CHECKOUT_DIR" ]] ; then + # Delete non-hidden files and directories + rm -rf "$CHECKOUT_DIR"/* + # Delete files and directories starting with . but excluding .. + rm -rf "$CHECKOUT_DIR"/.[!.]* + # Delete files and directories starting with .. plus any other character + rm -rf "$CHECKOUT_DIR"/..?* + fi + } + if [[ "$(params.deleteExisting)" == "true" ]] ; then + cleandir + fi + /ko-app/git-init \ + -url "$(params.url)" \ + -revision "$(params.revision)" \ + -path "$CHECKOUT_DIR" \ + -sslVerify="$(params.sslVerify)" \ + -submodules="$(params.submodules)" \ + -depth="$(params.depth)" + cd "$CHECKOUT_DIR" + RESULT_SHA="$(git rev-parse HEAD | tr -d '\n')" + EXIT_CODE="$?" + if [ "$EXIT_CODE" != 0 ] + then + exit $EXIT_CODE + fi + # Make sure we don't add a trailing newline to the result! + echo -n "$RESULT_SHA" > $(results.commit.path) \ No newline at end of file diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline/kaniko.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline/kaniko.yaml new file mode 100644 index 0000000..07f2c51 --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline/kaniko.yaml @@ -0,0 +1,63 @@ +# Copied from https://github.com/tektoncd/catalog/blob/v1beta1/kaniko/kaniko.yaml +# with a few fixes that will be port over in https://github.com/tektoncd/catalog/pull/291 +# Post #1839 we can refer to the remote Task in a registry or post #2298 in git directly +apiVersion: tekton.dev/v1beta1 +kind: Task +metadata: + name: kaniko +spec: + workspaces: + - name: source + params: + - name: IMAGE + description: Name (reference) of the image to build. + - name: DOCKERFILE + description: Path to the Dockerfile to build. + default: ./Dockerfile + - name: CONTEXT + description: The build context used by Kaniko. + default: ./ + - name: EXTRA_ARGS + default: "" + - name: BUILDER_IMAGE + description: The image on which builds will run + default: gcr.io/kaniko-project/executor:latest + results: + - name: IMAGE_DIGEST + description: Digest of the image just built. + steps: + - name: build-and-push + workingDir: $(workspaces.source.path) + image: $(params.BUILDER_IMAGE) + # specifying DOCKER_CONFIG is required to allow kaniko to detect docker credential + # https://github.com/tektoncd/pipeline/pull/706 + env: + - name: DOCKER_CONFIG + value: /tekton/home/.docker + command: + - /kaniko/executor + - $(params.EXTRA_ARGS) + - --dockerfile=$(params.DOCKERFILE) + - --context=$(workspaces.source.path)/$(params.CONTEXT) # The user does not need to care the workspace and the source. + - --destination=$(params.IMAGE) + - --oci-layout-path=$(workspaces.source.path)/$(params.CONTEXT)/image-digest + # kaniko assumes it is running as root, which means this example fails on platforms + # that default to run containers as random uid (like OpenShift). Adding this securityContext + # makes it explicit that it needs to run as root. + securityContext: + runAsUser: 0 + - name: write-digest + workingDir: $(workspaces.source.path) + image: ko://github.com/tektoncd/pipeline/cmd/imagedigestexporter + # output of imagedigestexport [{"name":"image","digest":"sha256:eed29..660"}] + command: ["/ko-app/imagedigestexporter"] + securityContext: + runAsUser: 0 + args: + - -images=[{"name":"$(params.IMAGE)","type":"image","url":"$(params.IMAGE)","digest":"","OutputImageDir":"$(workspaces.source.path)/$(params.CONTEXT)/image-digest"}] + - -terminationMessagePath=$(params.CONTEXT)/image-digested + - name: digest-to-results + workingDir: $(workspaces.source.path) + image: stedolan/jq + script: | + cat $(params.CONTEXT)/image-digested | jq '.[0].value' -rj | tee /tekton/results/IMAGE_DIGEST \ No newline at end of file diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline/source.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline/source.yaml new file mode 100644 index 0000000..8ae370b --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline/source.yaml @@ -0,0 +1,89 @@ +# This Pipeline Builds two microservice images(https://github.com/GoogleContainerTools/skaffold/tree/master/examples/microservices) +# from the Skaffold repo (https://github.com/GoogleContainerTools/skaffold) and deploys them to the repo currently running Tekton Pipelines. +apiVersion: tekton.dev/v1beta1 +kind: Pipeline +metadata: + name: demo-pipeline +spec: + params: + - name: image-registry + default: gcr.io/christiewilson-catfactory + workspaces: + - name: git-source + tasks: + - name: fetch-from-git + taskRef: + name: git-clone + params: + - name: url + value: https://github.com/GoogleContainerTools/skaffold + - name: revision + value: v0.32.0 + workspaces: + - name: output + workspace: git-source + - name: skaffold-unit-tests + runAfter: [fetch-from-git] + taskRef: + name: unit-tests + workspaces: + - name: source + workspace: git-source + - name: build-skaffold-web + runAfter: [skaffold-unit-tests] + taskRef: + name: kaniko + params: + - name: IMAGE + value: $(params.image-registry)/leeroy-web + - name: CONTEXT + value: examples/microservices/leeroy-web + - name: DOCKERFILE + value: $(workspaces.source.path)/examples/microservices/leeroy-web/Dockerfile + workspaces: + - name: source + workspace: git-source + - name: build-skaffold-app + runAfter: [skaffold-unit-tests] + taskRef: + name: kaniko + params: + - name: IMAGE + value: $(params.image-registry)/leeroy-app + - name: CONTEXT + value: examples/microservices/leeroy-app + - name: DOCKERFILE + value: $(workspaces.source.path)/examples/microservices/leeroy-app/Dockerfile + workspaces: + - name: source + workspace: git-source + - name: deploy-app + taskRef: + name: demo-deploy-kubectl + params: + - name: imageURL + value: $(params.image-registry)/leeroy-app@$(tasks.build-skaffold-app.results.IMAGE_DIGEST) + - name: path + value: $(workspaces.source.path)/examples/microservices/leeroy-app/kubernetes/deployment.yaml + - name: yqArg + value: "-d1" + - name: yamlPathToImage + value: "spec.template.spec.containers[0].image" + workspaces: + - name: source + workspace: git-source + - name: deploy-web + taskRef: + name: demo-deploy-kubectl + params: + - name: imageURL + value: $(params.image-registry)/leeroy-web@$(tasks.build-skaffold-web.results.IMAGE_DIGEST) + - name: path + value: $(workspaces.source.path)/examples/microservices/leeroy-web/kubernetes/deployment.yaml + - name: yqArg + value: "-d1" + - name: yamlPathToImage + value: "spec.template.spec.containers[0].image" + workspaces: + - name: source + workspace: git-source \ No newline at end of file diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline/unit-tests.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline/unit-tests.yaml new file mode 100644 index 0000000..f69fc77 --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pipeline/unit-tests.yaml @@ -0,0 +1,21 @@ +apiVersion: tekton.dev/v1beta1 +kind: Task +metadata: + name: unit-tests +spec: + workspaces: + - name: source + mountPath: /workspace/source/go/src/github.com/GoogleContainerTools/skaffold + steps: + - name: run-tests + image: golang + env: + - name: GOPATH + value: /workspace/go + workingDir: $(workspaces.source.path) + script: | + # The intention behind this example Task is to run unit test, however we + # currently do nothing to ensure that a unit test issue doesn't cause this example + # to fail unnecessarily. In the future we could re-introduce the unit tests (since + # we are now pinning the version of Skaffold we pull) or use Tekton Pipelines unit tests. + echo "pass" \ No newline at end of file diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pr-load-refs/add-params.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pr-load-refs/add-params.yaml new file mode 100644 index 0000000..bc00220 --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pr-load-refs/add-params.yaml @@ -0,0 +1,21 @@ +apiVersion: tekton.dev/v1beta1 +kind: Task +metadata: + name: add-params + annotations: + description: | + A simple task that sums the two provided integers +spec: + params: + - name: a + type: string + description: The first integer + - name: b + type: string + description: The second integer + steps: + - name: sum + image: bash:latest + script: | + #!/usr/bin/env bash + echo -n $(( "$(inputs.params.a)" + "$(inputs.params.b)" )) \ No newline at end of file diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pr-load-refs/expected.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pr-load-refs/expected.yaml new file mode 100644 index 0000000..c4ac2a7 --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pr-load-refs/expected.yaml @@ -0,0 +1,186 @@ +apiVersion: tekton.dev/v1beta1 +kind: PipelineRun +metadata: + annotations: + lighthouse.jenkins-x.io/loadFileRefs: .* + creationTimestamp: null + name: pipelinerun-with-extra-params +spec: + params: + - name: pl-param-x + value: "100" + - name: pl-param-y + value: "200" + - name: pl-param-z + value: "300" + pipelineSpec: + params: + - name: pl-param-x + type: string + - name: pl-param-y + type: string + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: '''the kind of job: postsubmit or presubmit''' + name: JOB_TYPE + type: string + - description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + - description: git url to clone + name: REPO_URL + type: string + tasks: + - name: add-params + params: + - name: a + value: $(params.pl-param-x) + - name: b + value: $(params.pl-param-y) + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + taskSpec: + metadata: {} + params: + - description: The first integer + name: a + type: string + - description: The second integer + name: b + type: string + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: '''the kind of job: postsubmit or presubmit''' + name: JOB_TYPE + type: string + - description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + - description: git url to clone + name: REPO_URL + type: string + spec: null + stepTemplate: + env: + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + name: "" + resources: {} + steps: + - image: bash:latest + name: sum + resources: {} + script: |- + #!/usr/bin/env bash + echo -n $(( "$(inputs.params.a)" + "$(inputs.params.b)" )) +status: {} diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pr-load-refs/pipeline-with-extra-params.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pr-load-refs/pipeline-with-extra-params.yaml new file mode 100644 index 0000000..0b5b66b --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pr-load-refs/pipeline-with-extra-params.yaml @@ -0,0 +1,19 @@ +apiVersion: tekton.dev/v1beta1 +kind: Pipeline +metadata: + name: pipeline-with-extra-params +spec: + params: + - name: pl-param-x + type: string + - name: pl-param-y + type: string + tasks: + - name: add-params + taskRef: + name: add-params + params: + - name: a + value: "$(params.pl-param-x)" + - name: b + value: "$(params.pl-param-y)" \ No newline at end of file diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pr-load-refs/source.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pr-load-refs/source.yaml new file mode 100644 index 0000000..70f464e --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/pr-load-refs/source.yaml @@ -0,0 +1,17 @@ +apiVersion: tekton.dev/v1beta1 +kind: PipelineRun +metadata: + name: pipelinerun-with-extra-params + annotations: + lighthouse.jenkins-x.io/loadFileRefs: ".*" +spec: + params: + - name: pl-param-x + value: "100" + - name: pl-param-y + value: "200" + # the extra parameter + - name: pl-param-z + value: "300" + pipelineRef: + name: pipeline-with-extra-params \ No newline at end of file diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/task-append-steps/expected.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/task-append-steps/expected.yaml new file mode 100644 index 0000000..c95efcd --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/task-append-steps/expected.yaml @@ -0,0 +1,178 @@ +apiVersion: tekton.dev/v1beta1 +kind: PipelineRun +metadata: + annotations: + lighthouse.jenkins-x.io/appendStepsURL: https://gist.githubusercontent.com/jstrachan/1937a809fd4223f3588db32cbb3a034f/raw/3bb56dd20cae2795e0ec4788d79e18d9486da9d9/sample-git-clone-task.yaml + creationTimestamp: null + name: cheese +spec: + pipelineSpec: + params: + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: '''the kind of job: postsubmit or presubmit''' + name: JOB_TYPE + type: string + - description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + - description: git url to clone + name: REPO_URL + type: string + tasks: + - name: cheese + params: + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + taskSpec: + metadata: {} + params: + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: '''the kind of job: postsubmit or presubmit''' + name: JOB_TYPE + type: string + - description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + - description: git url to clone + name: REPO_URL + type: string + spec: null + stepTemplate: + env: + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + name: "" + resources: {} + steps: + - image: some/linter:1.2.3 + name: lint + resources: {} + workingDir: /workspace/source + - image: gcr.io/jenkinsxio/builder-jx:2.1.142-761 + name: git-clone + resources: {} + script: | + #!/usr/bin/env bash + export SUBDIR="source" + echo "git cloning url: $REPO_URL version $PULL_PULL_SHA to dir: $SUBDIR" + git config --global --add user.name ${GIT_AUTHOR_NAME:-jenkins-x-bot} + git config --global --add user.email ${GIT_AUTHOR_EMAIL:-jenkins-x@googlegroups.com} + git config --global credential.helper store + git clone $REPO_URL $SUBDIR + cd $SUBDIR + git checkout $PULL_PULL_SHA + echo "checked out revision: $PULL_PULL_SHA to dir: $SUBDIR" + workingDir: /workspace +status: {} diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/task-append-steps/source.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/task-append-steps/source.yaml new file mode 100644 index 0000000..d7de53c --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/task-append-steps/source.yaml @@ -0,0 +1,11 @@ +apiVersion: tekton.dev/v1beta1 +kind: Task +metadata: + name: cheese + annotations: + "lighthouse.jenkins-x.io/appendStepsURL": "https://gist.githubusercontent.com/jstrachan/1937a809fd4223f3588db32cbb3a034f/raw/3bb56dd20cae2795e0ec4788d79e18d9486da9d9/sample-git-clone-task.yaml" +spec: + steps: + - image: some/linter:1.2.3 + name: lint + workingDir: /workspace/source diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/task-disable-params/expected.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/task-disable-params/expected.yaml new file mode 100644 index 0000000..d0c8b07 --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/task-disable-params/expected.yaml @@ -0,0 +1,140 @@ +apiVersion: tekton.dev/v1beta1 +kind: PipelineRun +metadata: + annotations: + lighthouse.jenkins-x.io/defaultParameters: "false" + creationTimestamp: null + name: cheese +spec: + pipelineSpec: + tasks: + - name: cheese + taskSpec: + metadata: {} + spec: null + stepTemplate: + name: "" + resources: + requests: + cpu: 400m + memory: 512Mi + volumeMounts: + - mountPath: /home/jenkins + name: workspace-volume + - mountPath: /etc/podinfo + name: podinfo + readOnly: true + workingDir: /workspace/source + steps: + - args: + - -c + - 'mkdir -p $HOME; git config --global --add user.name ${GIT_AUTHOR_NAME:-jenkins-x-bot}; + git config --global --add user.email ${GIT_AUTHOR_EMAIL:-jenkins-x@googlegroups.com}; + git config --global credential.helper store; git clone $(params.REPO_URL) + $(params.subdirectory); echo cloned url: $(params.REPO_URL) to dir: $(params.subdirectory); + cd $(params.subdirectory); git checkout $(params.PULL_PULL_SHA); echo + checked out revision: $(params.PULL_PULL_SHA) to dir: $(params.subdirectory)' + command: + - /bin/sh + image: gcr.io/jenkinsxio/builder-jx:2.1.142-761 + name: git-clone + resources: {} + workingDir: /workspace + - args: + - gitops + - git + - setup + - --namespace + - jx-git-operator + command: + - jx + image: gcr.io/jenkinsxio/jx-cli:latest + name: git-setup + resources: {} + workingDir: /workspace + - args: + - '[ -d /builder/home ] || mkdir -p /builder && ln -s /tekton/home /builder/home' + command: + - /bin/sh + - -c + image: gcr.io/jenkinsxio/builder-jx:2.1.142-761 + name: setup-builder-home + resources: {} + - args: + - step + - git + - merge + - --verbose + - --baseSHA + - $(params.PULL_BASE_SHA) + - --sha + - $(params.PULL_PULL_SHA) + - --baseBranch + - $(params.PULL_BASE_REF) + command: + - jx + image: gcr.io/jenkinsxio/builder-jx:2.1.142-761 + name: git-merge + resources: {} + - args: + - gitops + - variables + command: + - jx + image: gcr.io/jenkinsxio/jx-cli:latest + name: jx-variables + resources: {} + - args: + - jx step credential -s npm-token -k file -f /builder/home/.npmrc --optional=true + command: + - /bin/sh + - -c + image: gcr.io/jenkinsxio/builder-nodejs:2.1.150-769 + name: build-npmrc + resources: {} + - args: + - npm install + command: + - /bin/sh + - -c + image: gcr.io/jenkinsxio/builder-nodejs:2.1.150-769 + name: build-npm-install + resources: {} + - args: + - CI=true DISPLAY=:99 npm test + command: + - /bin/sh + - -c + image: gcr.io/jenkinsxio/builder-nodejs:2.1.150-769 + name: build-npm-test + resources: {} + - args: + - source .jx/variables.sh && cp /tekton/creds-secrets/tekton-container-registry-auth/.dockerconfigjson + /kaniko/.docker/config.json && /kaniko/executor $KANIKO_FLAGS --cache=true + --cache-dir=/workspace --context=/workspace/source --dockerfile=/workspace/source/Dockerfile + --destination=$DOCKER_REGISTRY/$DOCKER_REGISTRY_ORG/$APP_NAME:$VERSION + --cache-repo=$DOCKER_REGISTRY/$DOCKER_REGISTRY_ORG/cache + command: + - /busybox/sh + - -c + image: gcr.io/jenkinsxio/kaniko:0.0.5 + name: build-container-build + resources: {} + - args: + - source /workspace/source/.jx/variables.sh && jx preview create + command: + - /bin/bash + - -c + image: gcr.io/jenkinsxio/jx-cli:latest + name: promote-jx-preview + resources: {} + volumes: + - emptyDir: {} + name: workspace-volume + - downwardAPI: + items: + - fieldRef: + fieldPath: metadata.labels + path: labels + name: podinfo +status: {} diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/task-disable-params/source.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/task-disable-params/source.yaml new file mode 100644 index 0000000..b1ff55d --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/task-disable-params/source.yaml @@ -0,0 +1,122 @@ +apiVersion: tekton.dev/v1beta1 +kind: Task +metadata: + name: cheese + annotations: + lighthouse.jenkins-x.io/defaultParameters: "false" +spec: + stepTemplate: + resources: + requests: + cpu: 400m + memory: 512Mi + volumeMounts: + - mountPath: /home/jenkins + name: workspace-volume + - mountPath: /etc/podinfo + name: podinfo + readOnly: true + workingDir: /workspace/source + steps: + - args: + - -c + - 'mkdir -p $HOME; git config --global --add user.name ${GIT_AUTHOR_NAME:-jenkins-x-bot}; git config --global --add user.email ${GIT_AUTHOR_EMAIL:-jenkins-x@googlegroups.com}; git config --global credential.helper store; git clone $(params.REPO_URL) $(params.subdirectory); echo cloned url: $(params.REPO_URL) to dir: $(params.subdirectory); cd $(params.subdirectory); git checkout $(params.PULL_PULL_SHA); echo checked out revision: $(params.PULL_PULL_SHA) to dir: $(params.subdirectory)' + command: + - /bin/sh + image: gcr.io/jenkinsxio/builder-jx:2.1.142-761 + name: git-clone + resources: {} + workingDir: /workspace + - args: + - gitops + - git + - setup + - --namespace + - jx-git-operator + command: + - jx + image: gcr.io/jenkinsxio/jx-cli:latest + name: git-setup + resources: {} + workingDir: /workspace + - args: + - '[ -d /builder/home ] || mkdir -p /builder && ln -s /tekton/home /builder/home' + command: + - /bin/sh + - -c + image: gcr.io/jenkinsxio/builder-jx:2.1.142-761 + name: setup-builder-home + resources: {} + - args: + - step + - git + - merge + - --verbose + - --baseSHA + - $(params.PULL_BASE_SHA) + - --sha + - $(params.PULL_PULL_SHA) + - --baseBranch + - $(params.PULL_BASE_REF) + command: + - jx + image: gcr.io/jenkinsxio/builder-jx:2.1.142-761 + name: git-merge + resources: {} + - args: + - gitops + - variables + command: + - jx + image: gcr.io/jenkinsxio/jx-cli:latest + name: jx-variables + resources: {} + - args: + - jx step credential -s npm-token -k file -f /builder/home/.npmrc --optional=true + command: + - /bin/sh + - -c + image: gcr.io/jenkinsxio/builder-nodejs:2.1.150-769 + name: build-npmrc + resources: {} + - args: + - npm install + command: + - /bin/sh + - -c + image: gcr.io/jenkinsxio/builder-nodejs:2.1.150-769 + name: build-npm-install + resources: {} + - args: + - CI=true DISPLAY=:99 npm test + command: + - /bin/sh + - -c + image: gcr.io/jenkinsxio/builder-nodejs:2.1.150-769 + name: build-npm-test + resources: {} + - args: + - source .jx/variables.sh && cp /tekton/creds-secrets/tekton-container-registry-auth/.dockerconfigjson /kaniko/.docker/config.json && /kaniko/executor $KANIKO_FLAGS --cache=true --cache-dir=/workspace --context=/workspace/source --dockerfile=/workspace/source/Dockerfile --destination=$DOCKER_REGISTRY/$DOCKER_REGISTRY_ORG/$APP_NAME:$VERSION --cache-repo=$DOCKER_REGISTRY/$DOCKER_REGISTRY_ORG/cache + command: + - /busybox/sh + - -c + image: gcr.io/jenkinsxio/kaniko:0.0.5 + name: build-container-build + resources: {} + - args: + - source /workspace/source/.jx/variables.sh && jx preview create + command: + - /bin/bash + - -c + image: gcr.io/jenkinsxio/jx-cli:latest + name: promote-jx-preview + resources: {} + volumes: + - emptyDir: {} + name: workspace-volume + - downwardAPI: + items: + - fieldRef: + fieldPath: metadata.labels + path: labels + name: podinfo diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/task-prepend-steps/expected.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/task-prepend-steps/expected.yaml new file mode 100644 index 0000000..c3fc62e --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/task-prepend-steps/expected.yaml @@ -0,0 +1,178 @@ +apiVersion: tekton.dev/v1beta1 +kind: PipelineRun +metadata: + annotations: + lighthouse.jenkins-x.io/prependStepsURL: https://gist.githubusercontent.com/jstrachan/1937a809fd4223f3588db32cbb3a034f/raw/3bb56dd20cae2795e0ec4788d79e18d9486da9d9/sample-git-clone-task.yaml + creationTimestamp: null + name: cheese +spec: + pipelineSpec: + params: + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: '''the kind of job: postsubmit or presubmit''' + name: JOB_TYPE + type: string + - description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + - description: git url to clone + name: REPO_URL + type: string + tasks: + - name: cheese + params: + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + taskSpec: + metadata: {} + params: + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: '''the kind of job: postsubmit or presubmit''' + name: JOB_TYPE + type: string + - description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + - description: git url to clone + name: REPO_URL + type: string + spec: null + stepTemplate: + env: + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + name: "" + resources: {} + steps: + - image: gcr.io/jenkinsxio/builder-jx:2.1.142-761 + name: git-clone + resources: {} + script: | + #!/usr/bin/env bash + export SUBDIR="source" + echo "git cloning url: $REPO_URL version $PULL_PULL_SHA to dir: $SUBDIR" + git config --global --add user.name ${GIT_AUTHOR_NAME:-jenkins-x-bot} + git config --global --add user.email ${GIT_AUTHOR_EMAIL:-jenkins-x@googlegroups.com} + git config --global credential.helper store + git clone $REPO_URL $SUBDIR + cd $SUBDIR + git checkout $PULL_PULL_SHA + echo "checked out revision: $PULL_PULL_SHA to dir: $SUBDIR" + workingDir: /workspace + - image: some/linter:1.2.3 + name: lint + resources: {} + workingDir: /workspace/source +status: {} diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/task-prepend-steps/source.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/task-prepend-steps/source.yaml new file mode 100644 index 0000000..6e4e56e --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/task-prepend-steps/source.yaml @@ -0,0 +1,11 @@ +apiVersion: tekton.dev/v1beta1 +kind: Task +metadata: + name: cheese + annotations: + "lighthouse.jenkins-x.io/prependStepsURL": "https://gist.githubusercontent.com/jstrachan/1937a809fd4223f3588db32cbb3a034f/raw/3bb56dd20cae2795e0ec4788d79e18d9486da9d9/sample-git-clone-task.yaml" +spec: + steps: + - image: some/linter:1.2.3 + name: lint + workingDir: /workspace/source diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/task-without-params/expected.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/task-without-params/expected.yaml new file mode 100644 index 0000000..490c473 --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/task-without-params/expected.yaml @@ -0,0 +1,268 @@ +apiVersion: tekton.dev/v1beta1 +kind: PipelineRun +metadata: + creationTimestamp: null + name: cheese +spec: + pipelineSpec: + params: + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: '''the kind of job: postsubmit or presubmit''' + name: JOB_TYPE + type: string + - description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + - description: git url to clone + name: REPO_URL + type: string + tasks: + - name: cheese + params: + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + taskSpec: + metadata: {} + params: + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: '''the kind of job: postsubmit or presubmit''' + name: JOB_TYPE + type: string + - description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + - description: git url to clone + name: REPO_URL + type: string + spec: null + stepTemplate: + env: + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + name: "" + resources: + requests: + cpu: 400m + memory: 512Mi + volumeMounts: + - mountPath: /home/jenkins + name: workspace-volume + - mountPath: /etc/podinfo + name: podinfo + readOnly: true + workingDir: /workspace/source + steps: + - args: + - -c + - mkdir -p $HOME; git config --global --add user.name ${GIT_AUTHOR_NAME:-jenkins-x-bot}; + git config --global --add user.email ${GIT_AUTHOR_EMAIL:-jenkins-x@googlegroups.com}; + git config --global credential.helper store; git clone $REPO_URL + command: + - /bin/sh + image: gcr.io/jenkinsxio/builder-jx:2.1.142-761 + name: git-clone + resources: {} + workingDir: /workspace + - args: + - gitops + - git + - setup + - --namespace + - jx-git-operator + command: + - jx + image: gcr.io/jenkinsxio/jx-cli:latest + name: git-setup + resources: {} + workingDir: /workspace + - args: + - '[ -d /builder/home ] || mkdir -p /builder && ln -s /tekton/home /builder/home' + command: + - /bin/sh + - -c + image: gcr.io/jenkinsxio/builder-jx:2.1.142-761 + name: setup-builder-home + resources: {} + - args: + - step + - git + - merge + command: + - jx + image: gcr.io/jenkinsxio/builder-jx:2.1.142-761 + name: git-merge + resources: {} + - args: + - gitops + - variables + command: + - jx + image: gcr.io/jenkinsxio/jx-cli:latest + name: jx-variables + resources: {} + - args: + - jx step credential -s npm-token -k file -f /builder/home/.npmrc --optional=true + command: + - /bin/sh + - -c + image: gcr.io/jenkinsxio/builder-nodejs:2.1.150-769 + name: build-npmrc + resources: {} + - args: + - npm install + command: + - /bin/sh + - -c + image: gcr.io/jenkinsxio/builder-nodejs:2.1.150-769 + name: build-npm-install + resources: {} + - args: + - CI=true DISPLAY=:99 npm test + command: + - /bin/sh + - -c + image: gcr.io/jenkinsxio/builder-nodejs:2.1.150-769 + name: build-npm-test + resources: {} + - args: + - source .jx/variables.sh && cp /tekton/creds-secrets/tekton-container-registry-auth/.dockerconfigjson + /kaniko/.docker/config.json && /kaniko/executor $KANIKO_FLAGS --cache=true + --cache-dir=/workspace --context=/workspace/source --dockerfile=/workspace/source/Dockerfile + --destination=$DOCKER_REGISTRY/$DOCKER_REGISTRY_ORG/$APP_NAME:$VERSION + --cache-repo=$DOCKER_REGISTRY/$DOCKER_REGISTRY_ORG/cache + command: + - /busybox/sh + - -c + image: gcr.io/jenkinsxio/kaniko:0.0.5 + name: build-container-build + resources: {} + - args: + - source /workspace/source/.jx/variables.sh && jx preview create + command: + - /bin/bash + - -c + image: gcr.io/jenkinsxio/jx-cli:latest + name: promote-jx-preview + resources: {} + volumes: + - emptyDir: {} + name: workspace-volume + - downwardAPI: + items: + - fieldRef: + fieldPath: metadata.labels + path: labels + name: podinfo +status: {} diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/task-without-params/source.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/task-without-params/source.yaml new file mode 100644 index 0000000..16f5c02 --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/task-without-params/source.yaml @@ -0,0 +1,113 @@ +apiVersion: tekton.dev/v1beta1 +kind: Task +metadata: + name: cheese +spec: + stepTemplate: + resources: + requests: + cpu: 400m + memory: 512Mi + volumeMounts: + - mountPath: /home/jenkins + name: workspace-volume + - mountPath: /etc/podinfo + name: podinfo + readOnly: true + workingDir: /workspace/source + steps: + - args: + - -c + - 'mkdir -p $HOME; git config --global --add user.name ${GIT_AUTHOR_NAME:-jenkins-x-bot}; git config --global --add user.email ${GIT_AUTHOR_EMAIL:-jenkins-x@googlegroups.com}; git config --global credential.helper store; git clone $REPO_URL' + command: + - /bin/sh + image: gcr.io/jenkinsxio/builder-jx:2.1.142-761 + name: git-clone + resources: {} + workingDir: /workspace + - args: + - gitops + - git + - setup + - --namespace + - jx-git-operator + command: + - jx + image: gcr.io/jenkinsxio/jx-cli:latest + name: git-setup + resources: {} + workingDir: /workspace + - args: + - '[ -d /builder/home ] || mkdir -p /builder && ln -s /tekton/home /builder/home' + command: + - /bin/sh + - -c + image: gcr.io/jenkinsxio/builder-jx:2.1.142-761 + name: setup-builder-home + resources: {} + - args: + - step + - git + - merge + command: + - jx + image: gcr.io/jenkinsxio/builder-jx:2.1.142-761 + name: git-merge + resources: {} + - args: + - gitops + - variables + command: + - jx + image: gcr.io/jenkinsxio/jx-cli:latest + name: jx-variables + resources: {} + - args: + - jx step credential -s npm-token -k file -f /builder/home/.npmrc --optional=true + command: + - /bin/sh + - -c + image: gcr.io/jenkinsxio/builder-nodejs:2.1.150-769 + name: build-npmrc + resources: {} + - args: + - npm install + command: + - /bin/sh + - -c + image: gcr.io/jenkinsxio/builder-nodejs:2.1.150-769 + name: build-npm-install + resources: {} + - args: + - CI=true DISPLAY=:99 npm test + command: + - /bin/sh + - -c + image: gcr.io/jenkinsxio/builder-nodejs:2.1.150-769 + name: build-npm-test + resources: {} + - args: + - source .jx/variables.sh && cp /tekton/creds-secrets/tekton-container-registry-auth/.dockerconfigjson /kaniko/.docker/config.json && /kaniko/executor $KANIKO_FLAGS --cache=true --cache-dir=/workspace --context=/workspace/source --dockerfile=/workspace/source/Dockerfile --destination=$DOCKER_REGISTRY/$DOCKER_REGISTRY_ORG/$APP_NAME:$VERSION --cache-repo=$DOCKER_REGISTRY/$DOCKER_REGISTRY_ORG/cache + command: + - /busybox/sh + - -c + image: gcr.io/jenkinsxio/kaniko:0.0.5 + name: build-container-build + resources: {} + - args: + - source /workspace/source/.jx/variables.sh && jx preview create + command: + - /bin/bash + - -c + image: gcr.io/jenkinsxio/jx-cli:latest + name: promote-jx-preview + resources: {} + volumes: + - emptyDir: {} + name: workspace-volume + - downwardAPI: + items: + - fieldRef: + fieldPath: metadata.labels + path: labels + name: podinfo diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/task/expected.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/task/expected.yaml new file mode 100644 index 0000000..43eac25 --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/task/expected.yaml @@ -0,0 +1,319 @@ +apiVersion: tekton.dev/v1beta1 +kind: PipelineRun +metadata: + creationTimestamp: null + name: cheese +spec: + params: + - name: REPO_URL + value: "" + - name: PULL_PULL_SHA + value: master + - name: subdirectory + value: source + - name: BUILD_ID + value: "" + - name: JOB_NAME + value: "" + - name: JOB_SPEC + value: "" + - name: JOB_TYPE + value: "" + - name: PULL_BASE_REF + value: master + - name: PULL_BASE_SHA + value: "" + - name: PULL_NUMBER + value: "" + - name: PULL_PULL_REF + value: "" + - name: PULL_REFS + value: "" + - name: REPO_NAME + value: "" + - name: REPO_OWNER + value: "" + pipelineSpec: + params: + - description: git url to clone + name: REPO_URL + type: string + - default: master + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - default: source + description: subdirectory inside of /workspace to clone the git repo + name: subdirectory + type: string + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: 'the kind of job: postsubmit or presubmit' + name: JOB_TYPE + type: string + - default: master + description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + tasks: + - name: cheese + params: + - name: REPO_URL + value: $(params.REPO_URL) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: subdirectory + value: $(params.subdirectory) + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + taskSpec: + metadata: {} + params: + - description: git url to clone + name: REPO_URL + type: string + - default: master + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - default: source + description: subdirectory inside of /workspace to clone the git repo + name: subdirectory + type: string + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: 'the kind of job: postsubmit or presubmit' + name: JOB_TYPE + type: string + - default: master + description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + spec: null + stepTemplate: + env: + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + name: "" + resources: + requests: + cpu: 400m + memory: 512Mi + volumeMounts: + - mountPath: /home/jenkins + name: workspace-volume + - mountPath: /etc/podinfo + name: podinfo + readOnly: true + workingDir: /workspace/source + steps: + - args: + - -c + - 'mkdir -p $HOME; git config --global --add user.name ${GIT_AUTHOR_NAME:-jenkins-x-bot}; + git config --global --add user.email ${GIT_AUTHOR_EMAIL:-jenkins-x@googlegroups.com}; + git config --global credential.helper store; git clone $(params.REPO_URL) + $(params.subdirectory); echo cloned url: $(params.REPO_URL) to dir: $(params.subdirectory); + cd $(params.subdirectory); git checkout $(params.PULL_PULL_SHA); echo + checked out revision: $(params.PULL_PULL_SHA) to dir: $(params.subdirectory)' + command: + - /bin/sh + image: gcr.io/jenkinsxio/builder-jx:2.1.142-761 + name: git-clone + resources: {} + workingDir: /workspace + - args: + - gitops + - git + - setup + - --namespace + - jx-git-operator + command: + - jx + image: gcr.io/jenkinsxio/jx-cli:latest + name: git-setup + resources: {} + workingDir: /workspace + - args: + - '[ -d /builder/home ] || mkdir -p /builder && ln -s /tekton/home /builder/home' + command: + - /bin/sh + - -c + image: gcr.io/jenkinsxio/builder-jx:2.1.142-761 + name: setup-builder-home + resources: {} + - args: + - step + - git + - merge + - --verbose + - --baseSHA + - $(params.PULL_BASE_SHA) + - --sha + - $(params.PULL_PULL_SHA) + - --baseBranch + - $(params.PULL_BASE_REF) + command: + - jx + image: gcr.io/jenkinsxio/builder-jx:2.1.142-761 + name: git-merge + resources: {} + - args: + - gitops + - variables + command: + - jx + image: gcr.io/jenkinsxio/jx-cli:latest + name: jx-variables + resources: {} + - args: + - jx step credential -s npm-token -k file -f /builder/home/.npmrc --optional=true + command: + - /bin/sh + - -c + image: gcr.io/jenkinsxio/builder-nodejs:2.1.150-769 + name: build-npmrc + resources: {} + - args: + - npm install + command: + - /bin/sh + - -c + image: gcr.io/jenkinsxio/builder-nodejs:2.1.150-769 + name: build-npm-install + resources: {} + - args: + - CI=true DISPLAY=:99 npm test + command: + - /bin/sh + - -c + image: gcr.io/jenkinsxio/builder-nodejs:2.1.150-769 + name: build-npm-test + resources: {} + - args: + - source .jx/variables.sh && cp /tekton/creds-secrets/tekton-container-registry-auth/.dockerconfigjson + /kaniko/.docker/config.json && /kaniko/executor $KANIKO_FLAGS --cache=true + --cache-dir=/workspace --context=/workspace/source --dockerfile=/workspace/source/Dockerfile + --destination=$DOCKER_REGISTRY/$DOCKER_REGISTRY_ORG/$APP_NAME:$VERSION + --cache-repo=$DOCKER_REGISTRY/$DOCKER_REGISTRY_ORG/cache + command: + - /busybox/sh + - -c + image: gcr.io/jenkinsxio/kaniko:0.0.5 + name: build-container-build + resources: {} + - args: + - source /workspace/source/.jx/variables.sh && jx preview create + command: + - /bin/bash + - -c + image: gcr.io/jenkinsxio/jx-cli:latest + name: promote-jx-preview + resources: {} + volumes: + - emptyDir: {} + name: workspace-volume + - downwardAPI: + items: + - fieldRef: + fieldPath: metadata.labels + path: labels + name: podinfo +status: {} diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/task/source.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/task/source.yaml new file mode 100644 index 0000000..2799843 --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/task/source.yaml @@ -0,0 +1,196 @@ +apiVersion: tekton.dev/v1beta1 +kind: Task +metadata: + name: cheese +spec: + params: + - description: git url to clone + name: REPO_URL + type: string + - default: master + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - default: source + description: subdirectory inside of /workspace to clone the git repo + name: subdirectory + type: string + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: 'the kind of job: postsubmit or presubmit' + name: JOB_TYPE + type: string + - default: master + description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + stepTemplate: + env: + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + name: "" + resources: + requests: + cpu: 400m + memory: 512Mi + volumeMounts: + - mountPath: /home/jenkins + name: workspace-volume + - mountPath: /etc/podinfo + name: podinfo + readOnly: true + workingDir: /workspace/source + steps: + - args: + - -c + - 'mkdir -p $HOME; git config --global --add user.name ${GIT_AUTHOR_NAME:-jenkins-x-bot}; git config --global --add user.email ${GIT_AUTHOR_EMAIL:-jenkins-x@googlegroups.com}; git config --global credential.helper store; git clone $(params.REPO_URL) $(params.subdirectory); echo cloned url: $(params.REPO_URL) to dir: $(params.subdirectory); cd $(params.subdirectory); git checkout $(params.PULL_PULL_SHA); echo checked out revision: $(params.PULL_PULL_SHA) to dir: $(params.subdirectory)' + command: + - /bin/sh + image: gcr.io/jenkinsxio/builder-jx:2.1.142-761 + name: git-clone + resources: {} + workingDir: /workspace + - args: + - gitops + - git + - setup + - --namespace + - jx-git-operator + command: + - jx + image: gcr.io/jenkinsxio/jx-cli:latest + name: git-setup + resources: {} + workingDir: /workspace + - args: + - '[ -d /builder/home ] || mkdir -p /builder && ln -s /tekton/home /builder/home' + command: + - /bin/sh + - -c + image: gcr.io/jenkinsxio/builder-jx:2.1.142-761 + name: setup-builder-home + resources: {} + - args: + - step + - git + - merge + - --verbose + - --baseSHA + - $(params.PULL_BASE_SHA) + - --sha + - $(params.PULL_PULL_SHA) + - --baseBranch + - $(params.PULL_BASE_REF) + command: + - jx + image: gcr.io/jenkinsxio/builder-jx:2.1.142-761 + name: git-merge + resources: {} + - args: + - gitops + - variables + command: + - jx + image: gcr.io/jenkinsxio/jx-cli:latest + name: jx-variables + resources: {} + - args: + - jx step credential -s npm-token -k file -f /builder/home/.npmrc --optional=true + command: + - /bin/sh + - -c + image: gcr.io/jenkinsxio/builder-nodejs:2.1.150-769 + name: build-npmrc + resources: {} + - args: + - npm install + command: + - /bin/sh + - -c + image: gcr.io/jenkinsxio/builder-nodejs:2.1.150-769 + name: build-npm-install + resources: {} + - args: + - CI=true DISPLAY=:99 npm test + command: + - /bin/sh + - -c + image: gcr.io/jenkinsxio/builder-nodejs:2.1.150-769 + name: build-npm-test + resources: {} + - args: + - source .jx/variables.sh && cp /tekton/creds-secrets/tekton-container-registry-auth/.dockerconfigjson /kaniko/.docker/config.json && /kaniko/executor $KANIKO_FLAGS --cache=true --cache-dir=/workspace --context=/workspace/source --dockerfile=/workspace/source/Dockerfile --destination=$DOCKER_REGISTRY/$DOCKER_REGISTRY_ORG/$APP_NAME:$VERSION --cache-repo=$DOCKER_REGISTRY/$DOCKER_REGISTRY_ORG/cache + command: + - /busybox/sh + - -c + image: gcr.io/jenkinsxio/kaniko:0.0.5 + name: build-container-build + resources: {} + - args: + - source /workspace/source/.jx/variables.sh && jx preview create + command: + - /bin/bash + - -c + image: gcr.io/jenkinsxio/jx-cli:latest + name: promote-jx-preview + resources: {} + volumes: + - emptyDir: {} + name: workspace-volume + - downwardAPI: + items: + - fieldRef: + fieldPath: metadata.labels + path: labels + name: podinfo diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/taskrun/expected.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/taskrun/expected.yaml new file mode 100644 index 0000000..515ff34 --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/taskrun/expected.yaml @@ -0,0 +1,243 @@ +apiVersion: tekton.dev/v1beta1 +kind: PipelineRun +metadata: + creationTimestamp: null + name: cheese +spec: + pipelineSpec: + params: + - default: param-value + name: PARAM + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: '''the kind of job: postsubmit or presubmit''' + name: JOB_TYPE + type: string + - description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + - description: git url to clone + name: REPO_URL + type: string + tasks: + - name: cheese + params: + - name: PARAM + value: $(params.PARAM) + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + taskSpec: + metadata: {} + params: + - default: param-value + name: PARAM + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: '''the kind of job: postsubmit or presubmit''' + name: JOB_TYPE + type: string + - description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + - description: git url to clone + name: REPO_URL + type: string + spec: null + stepTemplate: + env: + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + name: "" + resources: {} + steps: + - image: ubuntu + name: noshebang + resources: {} + script: echo "no shebang" + - env: + - name: FOO + value: foooooooo + image: ubuntu + name: bash + resources: {} + script: | + #!/usr/bin/env bash + set -euxo pipefail + echo "Hello from Bash!" + echo FOO is ${FOO} + echo substring is ${FOO:2:4} + for i in {1..10}; do + echo line $i + done + - image: ubuntu + name: place-file + resources: {} + script: | + #!/usr/bin/env bash + echo "echo Hello from script file" > /workspace/hello + chmod +x /workspace/hello + - image: ubuntu + name: run-file + resources: {} + script: | + #!/usr/bin/env bash + /workspace/hello + - image: ubuntu + name: contains-eof + resources: {} + script: | + #!/usr/bin/env bash + cat > file << EOF + this file has some contents + EOF + cat file + - image: node + name: node + resources: {} + script: | + #!/usr/bin/env node + console.log("Hello from Node!") + - image: python + name: python + resources: {} + script: | + #!/usr/bin/env python3 + print("Hello from Python!") + - image: perl + name: perl + resources: {} + script: | + #!/usr/bin/perl + print "Hello from Perl!" + - image: python + name: params-applied + resources: {} + script: | + #!/usr/bin/env python3 + v = '$(params.PARAM)' + if v != 'param-value': + print('Param values not applied') + print('Got: ', v) + exit(1) + - args: + - hello + - world + image: ubuntu + name: args-allowed + resources: {} + script: |- + #!/usr/bin/env bash + [[ $# == 2 ]] + [[ $1 == "hello" ]] + [[ $2 == "world" ]] +status: {} diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/taskrun/source.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/taskrun/source.yaml new file mode 100644 index 0000000..23e84b8 --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/taskrun/source.yaml @@ -0,0 +1,81 @@ +apiVersion: tekton.dev/v1beta1 +kind: TaskRun +metadata: + generateName: step-script- + name: cheese +spec: + taskSpec: + params: + - name: PARAM + default: param-value + steps: + - name: noshebang + image: ubuntu + script: echo "no shebang" + - name: bash + image: ubuntu + env: + - name: FOO + value: foooooooo + script: | + #!/usr/bin/env bash + set -euxo pipefail + echo "Hello from Bash!" + echo FOO is ${FOO} + echo substring is ${FOO:2:4} + for i in {1..10}; do + echo line $i + done + - name: place-file + image: ubuntu + script: | + #!/usr/bin/env bash + echo "echo Hello from script file" > /workspace/hello + chmod +x /workspace/hello + - name: run-file + image: ubuntu + script: | + #!/usr/bin/env bash + /workspace/hello + - name: contains-eof + image: ubuntu + script: | + #!/usr/bin/env bash + cat > file << EOF + this file has some contents + EOF + cat file + - name: node + image: node + script: | + #!/usr/bin/env node + console.log("Hello from Node!") + - name: python + image: python + script: | + #!/usr/bin/env python3 + print("Hello from Python!") + - name: perl + image: perl + script: | + #!/usr/bin/perl + print "Hello from Perl!" + # Test that param values are replaced. + - name: params-applied + image: python + script: | + #!/usr/bin/env python3 + v = '$(params.PARAM)' + if v != 'param-value': + print('Param values not applied') + print('Got: ', v) + exit(1) + # Test that args are allowed and passed to the script as expected. + - name: args-allowed + image: ubuntu + args: ['hello', 'world'] + script: | + #!/usr/bin/env bash + [[ $# == 2 ]] + [[ $1 == "hello" ]] + [[ $2 == "world" ]] \ No newline at end of file diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-all-steps/README.md b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-all-steps/README.md new file mode 100644 index 0000000..cac7768 --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-all-steps/README.md @@ -0,0 +1,3 @@ +## Reuse all steps in a task + +This example shows how we can use `image: uses:sourceURI` to include all the steps in task \ No newline at end of file diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-all-steps/expected.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-all-steps/expected.yaml new file mode 100644 index 0000000..2e74f53 --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-all-steps/expected.yaml @@ -0,0 +1,243 @@ +apiVersion: tekton.dev/v1beta1 +kind: PipelineRun +metadata: + creationTimestamp: null + name: cheese +spec: + params: + - name: BUILD_ID + value: "" + - name: JOB_NAME + value: "" + - name: JOB_SPEC + value: "" + - name: JOB_TYPE + value: "" + - name: PULL_BASE_REF + value: "" + - name: PULL_BASE_SHA + value: "" + - name: PULL_NUMBER + value: "" + - name: PULL_PULL_REF + value: "" + - name: PULL_PULL_SHA + value: "" + - name: PULL_REFS + value: "" + - name: REPO_NAME + value: "" + - name: REPO_OWNER + value: "" + - name: REPO_URL + value: "" + pipelineSpec: + params: + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: '''the kind of job: postsubmit or presubmit''' + name: JOB_TYPE + type: string + - description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + - description: git url to clone + name: REPO_URL + type: string + tasks: + - name: from-build-pack + params: + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + taskSpec: + metadata: {} + params: + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: '''the kind of job: postsubmit or presubmit''' + name: JOB_TYPE + type: string + - description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + - description: git url to clone + name: REPO_URL + type: string + spec: null + stepTemplate: + env: + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + name: "" + resources: + requests: + cpu: 400m + memory: 512Mi + workingDir: /workspace/source + steps: + - image: gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/git-init:v0.19.0 + name: git-clone + resources: {} + script: | + #!/bin/sh + export SUBDIR="source" + echo "git cloning url: $REPO_URL version $PULL_PULL_SHA to dir: $SUBDIR" + git config --global --add user.name ${GIT_AUTHOR_NAME:-jenkins-x-bot} + git config --global --add user.email ${GIT_AUTHOR_EMAIL:-jenkins-x@googlegroups.com} + git config --global credential.helper store + git clone $REPO_URL $SUBDIR + cd $SUBDIR + git checkout $PULL_PULL_SHA + echo "checked out revision: $PULL_PULL_SHA to dir: $SUBDIR" + workingDir: /workspace + - image: gcr.io/jenkinsxio/jx-boot:3.1.62 + name: git-merge + resources: {} + script: | + #!/usr/bin/env sh + jx gitops git merge variables + workingDir: /workspace/source + - image: gcr.io/jenkinsxio/jx-boot:3.1.155 + name: jx-variables + resources: {} + script: | + #!/usr/bin/env sh + jx gitops variables + - image: node:12-slim + name: build-npm-install + resources: {} + script: | + #!/bin/sh + npm install + - image: node:12-slim + name: build-npm-test + resources: {} + script: | + #!/bin/sh + CI=true DISPLAY=:99 npm test + - image: gcr.io/kaniko-project/executor:debug-v1.3.0 + name: build-container-build + resources: {} + script: | + #!/busybox/sh + source .jx/variables.sh + cp /tekton/creds-secrets/tekton-container-registry-auth/.dockerconfigjson /kaniko/.docker/config.json + /kaniko/executor $KANIKO_FLAGS --context=/workspace/source --dockerfile=Dockerfile --destination=$DOCKER_REGISTRY/$DOCKER_REGISTRY_ORG/$APP_NAME:$VERSION + - image: gcr.io/jenkinsxio/jx-preview:0.0.143 + name: promote-jx-preview + resources: {} + script: | + #!/usr/bin/env sh + source .jx/variables.sh + jx preview create +status: {} diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-all-steps/source.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-all-steps/source.yaml new file mode 100644 index 0000000..02e6770 --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-all-steps/source.yaml @@ -0,0 +1,11 @@ +apiVersion: tekton.dev/v1beta1 +kind: PipelineRun +metadata: + name: cheese +spec: + pipelineSpec: + tasks: + - name: from-build-pack + taskSpec: + steps: + - image: uses:https://raw.githubusercontent.com/jenkins-x/jx3-pipeline-catalog/1d39235ee9235d7d52d4025a8e59cb8bda04306a/packs/javascript/.lighthouse/jenkins-x/pullrequest.yaml diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-custom-param-task/README.md b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-custom-param-task/README.md new file mode 100644 index 0000000..517c8c9 --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-custom-param-task/README.md @@ -0,0 +1 @@ +## Shows using custom parameters \ No newline at end of file diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-custom-param-task/expected.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-custom-param-task/expected.yaml new file mode 100644 index 0000000..4f460c1 --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-custom-param-task/expected.yaml @@ -0,0 +1,209 @@ +apiVersion: tekton.dev/v1beta1 +kind: PipelineRun +metadata: + creationTimestamp: null + name: params +spec: + params: + - name: FOO + value: BAR-CATALOG + - name: BUILD_ID + value: "" + - name: JOB_NAME + value: "" + - name: JOB_SPEC + value: "" + - name: JOB_TYPE + value: "" + - name: PULL_BASE_REF + value: "" + - name: PULL_BASE_SHA + value: "" + - name: PULL_NUMBER + value: "" + - name: PULL_PULL_REF + value: "" + - name: PULL_PULL_SHA + value: "" + - name: PULL_REFS + value: "" + - name: REPO_NAME + value: "" + - name: REPO_OWNER + value: "" + - name: REPO_URL + value: "" + pipelineSpec: + params: + - default: BAR-CATALOG + name: FOO + type: string + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: '''the kind of job: postsubmit or presubmit''' + name: JOB_TYPE + type: string + - description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + - description: git url to clone + name: REPO_URL + type: string + tasks: + - name: test-params + params: + - name: FOO + value: $(params.FOO) + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + resources: {} + taskSpec: + metadata: {} + params: + - default: BAR-CATALOG + name: FOO + type: string + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: '''the kind of job: postsubmit or presubmit''' + name: JOB_TYPE + type: string + - description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + - description: git url to clone + name: REPO_URL + type: string + resources: {} + spec: null + stepTemplate: + env: + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + - name: FOO + value: $(params.FOO) + name: "" + resources: + requests: + cpu: 400m + memory: 512Mi + steps: + - image: gcr.io/cloud-builders/kubectl@sha256:8ab94be8b2b4f3d117f02d868b39540fddd225447abf4014f7ba4765cb39f753 + name: test-echo + resources: {} + script: |- + #!/usr/bin/env bash + echo "FOO: $(params.FOO)" + podTemplate: {} + serviceAccountName: tekton-bot +status: {} diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-custom-param-task/source.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-custom-param-task/source.yaml new file mode 100644 index 0000000..4248754 --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-custom-param-task/source.yaml @@ -0,0 +1,30 @@ +apiVersion: tekton.dev/v1beta1 +kind: PipelineRun +metadata: + creationTimestamp: null + name: params +spec: + pipelineSpec: + tasks: + - name: test-params + params: + - name: FOO + value: $(params.FOO) + resources: { } + taskSpec: + metadata: { } + params: + - name: FOO + value: $(params.FOO) + stepTemplate: + image: uses:jenkins-x/jx3-pipeline-catalog/tasks/kubevirt/params.yaml@versionStream + name: "" + resources: + requests: + cpu: 400m + memory: 512Mi + steps: + - name: test-echo + resources: { } + podTemplate: { } + serviceAccountName: tekton-bot \ No newline at end of file diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-custom-param/README.md b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-custom-param/README.md new file mode 100644 index 0000000..517c8c9 --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-custom-param/README.md @@ -0,0 +1 @@ +## Shows using custom parameters \ No newline at end of file diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-custom-param/expected.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-custom-param/expected.yaml new file mode 100644 index 0000000..2e04660 --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-custom-param/expected.yaml @@ -0,0 +1,209 @@ +apiVersion: tekton.dev/v1beta1 +kind: PipelineRun +metadata: + creationTimestamp: null + name: params +spec: + params: + - name: FOO + value: BAR-CATALOG + - name: BUILD_ID + value: "" + - name: JOB_NAME + value: "" + - name: JOB_SPEC + value: "" + - name: JOB_TYPE + value: "" + - name: PULL_BASE_REF + value: "" + - name: PULL_BASE_SHA + value: "" + - name: PULL_NUMBER + value: "" + - name: PULL_PULL_REF + value: "" + - name: PULL_PULL_SHA + value: "" + - name: PULL_REFS + value: "" + - name: REPO_NAME + value: "" + - name: REPO_OWNER + value: "" + - name: REPO_URL + value: "" + pipelineSpec: + params: + - default: BAR-CATALOG + name: FOO + type: string + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: '''the kind of job: postsubmit or presubmit''' + name: JOB_TYPE + type: string + - description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + - description: git url to clone + name: REPO_URL + type: string + tasks: + - name: test-params + params: + - name: FOO + value: $(params.FOO) + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + resources: {} + taskSpec: + metadata: {} + params: + - default: BAR-CATALOG + name: FOO + type: string + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: '''the kind of job: postsubmit or presubmit''' + name: JOB_TYPE + type: string + - description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + - description: git url to clone + name: REPO_URL + type: string + resources: {} + spec: null + stepTemplate: + env: + - name: FOO + value: $(params.FOO) + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + name: "" + resources: + requests: + cpu: 400m + memory: 512Mi + steps: + - image: gcr.io/cloud-builders/kubectl@sha256:8ab94be8b2b4f3d117f02d868b39540fddd225447abf4014f7ba4765cb39f753 + name: test-echo + resources: {} + script: |- + #!/usr/bin/env bash + echo "FOO: $(params.FOO)" + podTemplate: {} + serviceAccountName: tekton-bot +status: {} diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-custom-param/source.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-custom-param/source.yaml new file mode 100644 index 0000000..389512e --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-custom-param/source.yaml @@ -0,0 +1,30 @@ +apiVersion: tekton.dev/v1beta1 +kind: PipelineRun +metadata: + creationTimestamp: null + name: params +spec: + pipelineSpec: + tasks: + - name: test-params + params: + - name: FOO + value: $(params.FOO) + resources: { } + taskSpec: + metadata: { } + params: + - name: FOO + value: $(params.FOO) + stepTemplate: + image: uses:jenkins-x/jx3-pipeline-catalog/tasks/kubevirt/params-task.yaml@versionStream + name: "" + resources: + requests: + cpu: 400m + memory: 512Mi + steps: + - name: test-echo + resources: { } + podTemplate: { } + serviceAccountName: tekton-bot \ No newline at end of file diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-issue-1234/README.md b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-issue-1234/README.md new file mode 100644 index 0000000..51c766f --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-issue-1234/README.md @@ -0,0 +1,3 @@ +## Replication of a issue 1234 + +https://github.com/jenkins-x/lighthouse-client/issues/1234 \ No newline at end of file diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-issue-1234/common.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-issue-1234/common.yaml new file mode 100644 index 0000000..c5f9e80 --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-issue-1234/common.yaml @@ -0,0 +1,15 @@ +apiVersion: tekton.dev/v1beta1 +kind: PipelineRun +metadata: + name: common +spec: + pipelineSpec: + tasks: + - name: common + taskSpec: + steps: + - image: common-image + name: common-build + env: + - name: FOO + value: foo diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-issue-1234/expected.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-issue-1234/expected.yaml new file mode 100644 index 0000000..b2fd5c4 --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-issue-1234/expected.yaml @@ -0,0 +1,190 @@ +apiVersion: tekton.dev/v1beta1 +kind: PipelineRun +metadata: + creationTimestamp: null + name: cheese +spec: + params: + - name: BUILD_ID + value: "" + - name: JOB_NAME + value: "" + - name: JOB_SPEC + value: "" + - name: JOB_TYPE + value: "" + - name: PULL_BASE_REF + value: "" + - name: PULL_BASE_SHA + value: "" + - name: PULL_NUMBER + value: "" + - name: PULL_PULL_REF + value: "" + - name: PULL_PULL_SHA + value: "" + - name: PULL_REFS + value: "" + - name: REPO_NAME + value: "" + - name: REPO_OWNER + value: "" + - name: REPO_URL + value: "" + pipelineSpec: + params: + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: '''the kind of job: postsubmit or presubmit''' + name: JOB_TYPE + type: string + - description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + - description: git url to clone + name: REPO_URL + type: string + tasks: + - name: from-build-pack + params: + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + taskSpec: + metadata: {} + params: + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: '''the kind of job: postsubmit or presubmit''' + name: JOB_TYPE + type: string + - description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + - description: git url to clone + name: REPO_URL + type: string + spec: null + stepTemplate: + env: + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + name: "" + resources: {} + steps: + - env: + - name: FOO + value: one + image: common-image + name: common-build + resources: {} +status: {} diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-issue-1234/expected2.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-issue-1234/expected2.yaml new file mode 100644 index 0000000..1b88ba2 --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-issue-1234/expected2.yaml @@ -0,0 +1,190 @@ +apiVersion: tekton.dev/v1beta1 +kind: PipelineRun +metadata: + creationTimestamp: null + name: cheese +spec: + params: + - name: BUILD_ID + value: "" + - name: JOB_NAME + value: "" + - name: JOB_SPEC + value: "" + - name: JOB_TYPE + value: "" + - name: PULL_BASE_REF + value: "" + - name: PULL_BASE_SHA + value: "" + - name: PULL_NUMBER + value: "" + - name: PULL_PULL_REF + value: "" + - name: PULL_PULL_SHA + value: "" + - name: PULL_REFS + value: "" + - name: REPO_NAME + value: "" + - name: REPO_OWNER + value: "" + - name: REPO_URL + value: "" + pipelineSpec: + params: + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: '''the kind of job: postsubmit or presubmit''' + name: JOB_TYPE + type: string + - description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + - description: git url to clone + name: REPO_URL + type: string + tasks: + - name: from-build-pack + params: + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + taskSpec: + metadata: {} + params: + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: '''the kind of job: postsubmit or presubmit''' + name: JOB_TYPE + type: string + - description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + - description: git url to clone + name: REPO_URL + type: string + spec: null + stepTemplate: + env: + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + name: "" + resources: {} + steps: + - env: + - name: FOO + value: foo + image: common-image + name: common-build + resources: {} +status: {} diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-issue-1234/source.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-issue-1234/source.yaml new file mode 100644 index 0000000..23fdf19 --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-issue-1234/source.yaml @@ -0,0 +1,15 @@ +apiVersion: tekton.dev/v1beta1 +kind: PipelineRun +metadata: + name: cheese +spec: + pipelineSpec: + tasks: + - name: from-build-pack + taskSpec: + steps: + - image: uses:./test_data/load_pipelinerun/uses-issue-1234/common.yaml + name: common-build + env: + - name: FOO + value: one diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-issue-1234/source2.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-issue-1234/source2.yaml new file mode 100644 index 0000000..82ef0bc --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-issue-1234/source2.yaml @@ -0,0 +1,12 @@ +apiVersion: tekton.dev/v1beta1 +kind: PipelineRun +metadata: + name: cheese +spec: + pipelineSpec: + tasks: + - name: from-build-pack + taskSpec: + steps: + - image: uses:./test_data/load_pipelinerun/uses-issue-1234/common.yaml + name: common-build \ No newline at end of file diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-add-custom-explict/README.md b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-add-custom-explict/README.md new file mode 100644 index 0000000..bf0ba01 --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-add-custom-explict/README.md @@ -0,0 +1,5 @@ +## Reuse steps in a task mixed with custom tasks + +This example shows how we can use `image: uses:sourceURI` and a `name: mystep` to include individual the steps in task and mix them with custom local steps (which don't use `uses:`) + +This example uses the verbose syntax where each step always has an image (rather than inheriting from `stepTemplate.image`) \ No newline at end of file diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-add-custom-explict/expected.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-add-custom-explict/expected.yaml new file mode 100644 index 0000000..b2d546f --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-add-custom-explict/expected.yaml @@ -0,0 +1,239 @@ +apiVersion: tekton.dev/v1beta1 +kind: PipelineRun +metadata: + creationTimestamp: null + name: cheese +spec: + params: + - name: BUILD_ID + value: "" + - name: JOB_NAME + value: "" + - name: JOB_SPEC + value: "" + - name: JOB_TYPE + value: "" + - name: PULL_BASE_REF + value: "" + - name: PULL_BASE_SHA + value: "" + - name: PULL_NUMBER + value: "" + - name: PULL_PULL_REF + value: "" + - name: PULL_PULL_SHA + value: "" + - name: PULL_REFS + value: "" + - name: REPO_NAME + value: "" + - name: REPO_OWNER + value: "" + - name: REPO_URL + value: "" + pipelineSpec: + params: + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: '''the kind of job: postsubmit or presubmit''' + name: JOB_TYPE + type: string + - description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + - description: git url to clone + name: REPO_URL + type: string + tasks: + - name: from-build-pack + params: + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + taskSpec: + metadata: {} + params: + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: '''the kind of job: postsubmit or presubmit''' + name: JOB_TYPE + type: string + - description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + - description: git url to clone + name: REPO_URL + type: string + spec: null + stepTemplate: + env: + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + name: "" + resources: + requests: + cpu: 400m + memory: 512Mi + workingDir: /workspace/source + steps: + - image: node:12-slim + name: my-first-step + resources: {} + script: | + #!/bin/sh + npm first thing + - image: gcr.io/jenkinsxio/jx-boot:3.1.155 + name: jx-variables + resources: {} + script: | + #!/usr/bin/env sh + jx gitops variables + - image: node:12-slim + name: build-npm-install + resources: {} + script: | + #!/bin/sh + npm install + - image: node:12-slim + name: build-npm-test + resources: {} + script: | + #!/bin/sh + CI=true DISPLAY=:99 npm test + - image: node:12-slim + name: my-pre-build-container + resources: {} + script: | + #!/bin/sh + npm pre build container + - image: gcr.io/kaniko-project/executor:debug-v1.3.0 + name: build-container-build + resources: {} + script: | + #!/busybox/sh + source .jx/variables.sh + cp /tekton/creds-secrets/tekton-container-registry-auth/.dockerconfigjson /kaniko/.docker/config.json + /kaniko/executor $KANIKO_FLAGS --context=/workspace/source --dockerfile=Dockerfile --destination=$DOCKER_REGISTRY/$DOCKER_REGISTRY_ORG/$APP_NAME:$VERSION + - image: gcr.io/jenkinsxio/jx-preview:0.0.143 + name: promote-jx-preview + resources: {} + script: | + #!/usr/bin/env sh + source .jx/variables.sh + jx preview create + - image: node:12-slim + name: my-final-step + resources: {} + script: | + #!/bin/sh + npm final thing +status: {} diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-add-custom-explict/source.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-add-custom-explict/source.yaml new file mode 100644 index 0000000..969fd43 --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-add-custom-explict/source.yaml @@ -0,0 +1,35 @@ +apiVersion: tekton.dev/v1beta1 +kind: PipelineRun +metadata: + name: cheese +spec: + pipelineSpec: + tasks: + - name: from-build-pack + taskSpec: + steps: + - image: node:12-slim + name: my-first-step + script: | + #!/bin/sh + npm first thing + - image: uses:https://raw.githubusercontent.com/jenkins-x/jx3-pipeline-catalog/1d39235ee9235d7d52d4025a8e59cb8bda04306a/packs/javascript/.lighthouse/jenkins-x/pullrequest.yaml + name: jx-variables + - image: uses:https://raw.githubusercontent.com/jenkins-x/jx3-pipeline-catalog/1d39235ee9235d7d52d4025a8e59cb8bda04306a/packs/javascript/.lighthouse/jenkins-x/pullrequest.yaml + name: build-npm-install + - image: uses:https://raw.githubusercontent.com/jenkins-x/jx3-pipeline-catalog/1d39235ee9235d7d52d4025a8e59cb8bda04306a/packs/javascript/.lighthouse/jenkins-x/pullrequest.yaml + name: build-npm-test + - image: node:12-slim + name: my-pre-build-container + script: | + #!/bin/sh + npm pre build container + - image: uses:https://raw.githubusercontent.com/jenkins-x/jx3-pipeline-catalog/1d39235ee9235d7d52d4025a8e59cb8bda04306a/packs/javascript/.lighthouse/jenkins-x/pullrequest.yaml + name: build-container-build + - image: uses:https://raw.githubusercontent.com/jenkins-x/jx3-pipeline-catalog/1d39235ee9235d7d52d4025a8e59cb8bda04306a/packs/javascript/.lighthouse/jenkins-x/pullrequest.yaml + name: promote-jx-preview + - image: node:12-slim + name: my-final-step + script: | + #!/bin/sh + npm final thing diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-add-custom/README.md b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-add-custom/README.md new file mode 100644 index 0000000..ebe47f4 --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-add-custom/README.md @@ -0,0 +1,5 @@ +## Reuse steps in a task mixed with custom tasks + +This example shows how we can use `image: uses:sourceURI` and a `name: mystep` to include individual the steps in task and mix them with custom local steps (which don't use `uses:`) + +This example uses the concise syntax; where empty `image:` values get inherited from the `stepTemplate.image` diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-add-custom/expected.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-add-custom/expected.yaml new file mode 100644 index 0000000..b2d546f --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-add-custom/expected.yaml @@ -0,0 +1,239 @@ +apiVersion: tekton.dev/v1beta1 +kind: PipelineRun +metadata: + creationTimestamp: null + name: cheese +spec: + params: + - name: BUILD_ID + value: "" + - name: JOB_NAME + value: "" + - name: JOB_SPEC + value: "" + - name: JOB_TYPE + value: "" + - name: PULL_BASE_REF + value: "" + - name: PULL_BASE_SHA + value: "" + - name: PULL_NUMBER + value: "" + - name: PULL_PULL_REF + value: "" + - name: PULL_PULL_SHA + value: "" + - name: PULL_REFS + value: "" + - name: REPO_NAME + value: "" + - name: REPO_OWNER + value: "" + - name: REPO_URL + value: "" + pipelineSpec: + params: + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: '''the kind of job: postsubmit or presubmit''' + name: JOB_TYPE + type: string + - description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + - description: git url to clone + name: REPO_URL + type: string + tasks: + - name: from-build-pack + params: + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + taskSpec: + metadata: {} + params: + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: '''the kind of job: postsubmit or presubmit''' + name: JOB_TYPE + type: string + - description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + - description: git url to clone + name: REPO_URL + type: string + spec: null + stepTemplate: + env: + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + name: "" + resources: + requests: + cpu: 400m + memory: 512Mi + workingDir: /workspace/source + steps: + - image: node:12-slim + name: my-first-step + resources: {} + script: | + #!/bin/sh + npm first thing + - image: gcr.io/jenkinsxio/jx-boot:3.1.155 + name: jx-variables + resources: {} + script: | + #!/usr/bin/env sh + jx gitops variables + - image: node:12-slim + name: build-npm-install + resources: {} + script: | + #!/bin/sh + npm install + - image: node:12-slim + name: build-npm-test + resources: {} + script: | + #!/bin/sh + CI=true DISPLAY=:99 npm test + - image: node:12-slim + name: my-pre-build-container + resources: {} + script: | + #!/bin/sh + npm pre build container + - image: gcr.io/kaniko-project/executor:debug-v1.3.0 + name: build-container-build + resources: {} + script: | + #!/busybox/sh + source .jx/variables.sh + cp /tekton/creds-secrets/tekton-container-registry-auth/.dockerconfigjson /kaniko/.docker/config.json + /kaniko/executor $KANIKO_FLAGS --context=/workspace/source --dockerfile=Dockerfile --destination=$DOCKER_REGISTRY/$DOCKER_REGISTRY_ORG/$APP_NAME:$VERSION + - image: gcr.io/jenkinsxio/jx-preview:0.0.143 + name: promote-jx-preview + resources: {} + script: | + #!/usr/bin/env sh + source .jx/variables.sh + jx preview create + - image: node:12-slim + name: my-final-step + resources: {} + script: | + #!/bin/sh + npm final thing +status: {} diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-add-custom/source.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-add-custom/source.yaml new file mode 100644 index 0000000..4f8855a --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-add-custom/source.yaml @@ -0,0 +1,32 @@ +apiVersion: tekton.dev/v1beta1 +kind: PipelineRun +metadata: + name: cheese +spec: + pipelineSpec: + tasks: + - name: from-build-pack + taskSpec: + stepTemplate: + image: uses:https://raw.githubusercontent.com/jenkins-x/jx3-pipeline-catalog/1d39235ee9235d7d52d4025a8e59cb8bda04306a/packs/javascript/.lighthouse/jenkins-x/pullrequest.yaml + steps: + - image: node:12-slim + name: my-first-step + script: | + #!/bin/sh + npm first thing + - name: jx-variables + - name: build-npm-install + - name: build-npm-test + - image: node:12-slim + name: my-pre-build-container + script: | + #!/bin/sh + npm pre build container + - name: build-container-build + - name: promote-jx-preview + - image: node:12-slim + name: my-final-step + script: | + #!/bin/sh + npm final thing diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-custom-git/README.md b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-custom-git/README.md new file mode 100644 index 0000000..3ac1aa9 --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-custom-git/README.md @@ -0,0 +1,3 @@ +## Reuse steps in a task + +This example shows how we can use `image: uses:sourceURI` and a `name: mystep` to include individual the steps in task using both both github repository and the local lighthouse git server \ No newline at end of file diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-custom-git/expected.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-custom-git/expected.yaml new file mode 100644 index 0000000..a2c7956 --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-custom-git/expected.yaml @@ -0,0 +1,469 @@ +apiVersion: tekton.dev/v1beta1 +kind: PipelineRun +metadata: + creationTimestamp: null + name: cheese +spec: + params: + - name: url + value: "" + - name: revision + value: "" + - name: refspec + value: "" + - name: submodules + value: "true" + - name: depth + value: "1" + - name: sslVerify + value: "true" + - name: subdirectory + value: "" + - name: deleteExisting + value: "true" + - name: httpProxy + value: "" + - name: httpsProxy + value: "" + - name: noProxy + value: "" + - name: verbose + value: "true" + - name: gitInitImage + value: gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/git-init:v0.18.1 + - name: BUILD_ID + value: "" + - name: JOB_NAME + value: "" + - name: JOB_SPEC + value: "" + - name: JOB_TYPE + value: "" + - name: PULL_BASE_REF + value: "" + - name: PULL_BASE_SHA + value: "" + - name: PULL_NUMBER + value: "" + - name: PULL_PULL_REF + value: "" + - name: PULL_PULL_SHA + value: "" + - name: PULL_REFS + value: "" + - name: REPO_NAME + value: "" + - name: REPO_OWNER + value: "" + - name: REPO_URL + value: "" + pipelineSpec: + params: + - description: git url to clone + name: url + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: revision + type: string + - default: "" + description: (optional) git refspec to fetch before checking out revision + name: refspec + type: string + - default: "true" + description: defines if the resource should initialize and fetch the submodules + name: submodules + type: string + - default: "1" + description: performs a shallow clone where only the most recent commit(s) will + be fetched + name: depth + type: string + - default: "true" + description: defines if http.sslVerify should be set to true or false in the + global git config + name: sslVerify + type: string + - default: "" + description: subdirectory inside the "output" workspace to clone the git repo + into + name: subdirectory + type: string + - default: "true" + description: clean out the contents of the repo's destination directory (if + it already exists) before trying to clone the repo there + name: deleteExisting + type: string + - default: "" + description: git HTTP proxy server for non-SSL requests + name: httpProxy + type: string + - default: "" + description: git HTTPS proxy server for SSL requests + name: httpsProxy + type: string + - default: "" + description: git no proxy - opt out of proxying HTTP/HTTPS requests + name: noProxy + type: string + - default: "true" + description: log the commands used during execution + name: verbose + type: string + - default: gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/git-init:v0.18.1 + description: the image used where the git-init binary is + name: gitInitImage + type: string + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: '''the kind of job: postsubmit or presubmit''' + name: JOB_TYPE + type: string + - description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + - description: git url to clone + name: REPO_URL + type: string + results: + - description: The precise commit SHA that was fetched by this Task + name: commit + value: $(tasks.from-build-pack.results.commit) + - description: The precise URL that was fetched by this Task + name: url + value: $(tasks.from-build-pack.results.url) + tasks: + - name: from-build-pack + params: + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + taskSpec: + metadata: {} + params: + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: '''the kind of job: postsubmit or presubmit''' + name: JOB_TYPE + type: string + - description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + - description: git url to clone + name: REPO_URL + type: string + - description: git url to clone + name: url + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: revision + type: string + - default: "" + description: (optional) git refspec to fetch before checking out revision + name: refspec + type: string + - default: "true" + description: defines if the resource should initialize and fetch the submodules + name: submodules + type: string + - default: "1" + description: performs a shallow clone where only the most recent commit(s) + will be fetched + name: depth + type: string + - default: "true" + description: defines if http.sslVerify should be set to true or false in + the global git config + name: sslVerify + type: string + - default: "" + description: subdirectory inside the "output" workspace to clone the git + repo into + name: subdirectory + type: string + - default: "true" + description: clean out the contents of the repo's destination directory + (if it already exists) before trying to clone the repo there + name: deleteExisting + type: string + - default: "" + description: git HTTP proxy server for non-SSL requests + name: httpProxy + type: string + - default: "" + description: git HTTPS proxy server for SSL requests + name: httpsProxy + type: string + - default: "" + description: git no proxy - opt out of proxying HTTP/HTTPS requests + name: noProxy + type: string + - default: "true" + description: log the commands used during execution + name: verbose + type: string + - default: gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/git-init:v0.18.1 + description: the image used where the git-init binary is + name: gitInitImage + type: string + results: + - description: The precise commit SHA that was fetched by this Task + name: commit + - description: The precise URL that was fetched by this Task + name: url + spec: null + stepTemplate: + env: + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + name: "" + resources: + requests: + cpu: 400m + memory: 512Mi + volumeMounts: + - mountPath: /tekton/home/npm + name: npmrc + workingDir: /workspace/source + steps: + - env: + - name: PARAM_URL + value: $(params.url) + - name: PARAM_REVISION + value: $(params.revision) + - name: PARAM_REFSPEC + value: $(params.refspec) + - name: PARAM_SUBMODULES + value: $(params.submodules) + - name: PARAM_DEPTH + value: $(params.depth) + - name: PARAM_SSL_VERIFY + value: $(params.sslVerify) + - name: PARAM_SUBDIRECTORY + value: $(params.subdirectory) + - name: PARAM_DELETE_EXISTING + value: $(params.deleteExisting) + - name: PARAM_HTTP_PROXY + value: $(params.httpProxy) + - name: PARAM_HTTPS_PROXY + value: $(params.httpsProxy) + - name: PARAM_NO_PROXY + value: $(params.noProxy) + - name: PARAM_VERBOSE + value: $(params.verbose) + - name: WORKSPACE_OUTPUT_PATH + value: $(workspaces.output.path) + image: $(params.gitInitImage) + name: clone + resources: {} + script: | + #!/bin/sh + set -eu -o pipefail + + if [[ "${PARAM_VERBOSE}" == "true" ]] ; then + set -x + fi + + CHECKOUT_DIR="${WORKSPACE_OUTPUT_PATH}/${PARAM_SUBDIRECTORY}" + + cleandir() { + # Delete any existing contents of the repo directory if it exists. + # + # We don't just "rm -rf $CHECKOUT_DIR" because $CHECKOUT_DIR might be "/" + # or the root of a mounted volume. + if [[ -d "$CHECKOUT_DIR" ]] ; then + # Delete non-hidden files and directories + rm -rf "$CHECKOUT_DIR"/* + # Delete files and directories starting with . but excluding .. + rm -rf "$CHECKOUT_DIR"/.[!.]* + # Delete files and directories starting with .. plus any other character + rm -rf "$CHECKOUT_DIR"/..?* + fi + } + + if [[ "${PARAM_DELETE_EXISTING}" == "true" ]] ; then + cleandir + fi + + test -z "${PARAM_HTTP_PROXY}" || export HTTP_PROXY="${PARAM_HTTP_PROXY}" + test -z "${PARAM_HTTPS_PROXY}" || export HTTPS_PROXY="${PARAM_HTTPS_PROXY}" + test -z "${PARAM_NO_PROXY}" || export NO_PROXY="${PARAM_NO_PROXY}" + + /ko-app/git-init \ + -url "${PARAM_URL}" \ + -revision "${PARAM_REVISION}" \ + -refspec "${PARAM_REFSPEC}" \ + -path "$CHECKOUT_DIR" \ + -sslVerify="${PARAM_SSL_VERIFY}" \ + -submodules="${PARAM_SUBMODULES}" \ + -depth "${PARAM_DEPTH}" + cd "$CHECKOUT_DIR" + RESULT_SHA="$(git rev-parse HEAD)" + EXIT_CODE="$?" + if [ "$EXIT_CODE" != 0 ] ; then + exit $EXIT_CODE + fi + # ensure we don't add a trailing newline to the result + echo -n "$RESULT_SHA" > $(results.commit.path) + echo -n "${PARAM_URL}" > $(results.url.path) + - image: gcr.io/jenkinsxio/jx-boot:3.1.155 + name: jx-variables + resources: {} + script: | + #!/usr/bin/env sh + jx gitops variables + - image: node:12-slim + name: build-npm-install + resources: {} + script: | + #!/bin/sh + npm install + - image: node:12-slim + name: build-npm-test + resources: {} + script: | + #!/bin/sh + CI=true DISPLAY=:99 npm test + - image: gcr.io/kaniko-project/executor:debug-v1.3.0 + name: build-container-build + resources: {} + script: | + #!/busybox/sh + source .jx/variables.sh + cp /tekton/creds-secrets/tekton-container-registry-auth/.dockerconfigjson /kaniko/.docker/config.json + /kaniko/executor $KANIKO_FLAGS --context=/workspace/source --dockerfile=Dockerfile --destination=$DOCKER_REGISTRY/$DOCKER_REGISTRY_ORG/$APP_NAME:$VERSION + - image: gcr.io/jenkinsxio/jx-preview:0.0.143 + name: promote-jx-preview + resources: {} + script: | + #!/usr/bin/env sh + source .jx/variables.sh + jx preview create + volumes: + - name: npmrc + secret: + optional: true + secretName: npmrc + workspaces: + - description: The git repo will be cloned onto the volume backing this workspace + name: output + workspaces: + - name: output + workspace: output + workspaces: + - description: The git repo will be cloned onto the volume backing this workspace + name: output + workspaces: + - emptyDir: {} + name: output +status: {} diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-custom-git/source.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-custom-git/source.yaml new file mode 100644 index 0000000..47b2495 --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-custom-git/source.yaml @@ -0,0 +1,26 @@ +apiVersion: tekton.dev/v1beta1 +kind: PipelineRun +metadata: + name: cheese +spec: + pipelineSpec: + tasks: + - name: from-build-pack + taskSpec: + workspaces: + - name: output + persistentVolumeClaim: + claimName: "cheese" + stepTemplate: + image: uses:lighthouse:jenkins-x/jx3-pipeline-catalog/packs/javascript/.lighthouse/jenkins-x/pullrequest.yaml@1d39235ee9235d7d52d4025a8e59cb8bda04306a + steps: + - name: clone + image: uses:tektoncd/catalog/task/git-clone/0.2/git-clone.yaml@HEAD + - name: jx-variables + - name: build-npm-install + - name: build-npm-test + - name: build-container-build + - name: promote-jx-preview + + + diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-explicit/README.md b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-explicit/README.md new file mode 100644 index 0000000..e4b79ec --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-explicit/README.md @@ -0,0 +1,5 @@ +## Reuse steps in a task + +This example shows how we can use `image: uses:sourceURI` and a `name: mystep` to include individual the steps in task + +This example uses the verbose syntax where each step always has an image (rather than inheriting from `stepTemplate.image`) \ No newline at end of file diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-explicit/expected.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-explicit/expected.yaml new file mode 100644 index 0000000..c5edf08 --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-explicit/expected.yaml @@ -0,0 +1,229 @@ +apiVersion: tekton.dev/v1beta1 +kind: PipelineRun +metadata: + creationTimestamp: null + name: cheese +spec: + params: + - name: BUILD_ID + value: "" + - name: JOB_NAME + value: "" + - name: JOB_SPEC + value: "" + - name: JOB_TYPE + value: "" + - name: PULL_BASE_REF + value: "" + - name: PULL_BASE_SHA + value: "" + - name: PULL_NUMBER + value: "" + - name: PULL_PULL_REF + value: "" + - name: PULL_PULL_SHA + value: "" + - name: PULL_REFS + value: "" + - name: REPO_NAME + value: "" + - name: REPO_OWNER + value: "" + - name: REPO_URL + value: "" + pipelineSpec: + params: + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: '''the kind of job: postsubmit or presubmit''' + name: JOB_TYPE + type: string + - description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + - description: git url to clone + name: REPO_URL + type: string + tasks: + - name: from-build-pack + params: + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + taskSpec: + metadata: {} + params: + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: '''the kind of job: postsubmit or presubmit''' + name: JOB_TYPE + type: string + - description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + - description: git url to clone + name: REPO_URL + type: string + spec: null + stepTemplate: + env: + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + name: "" + resources: + requests: + cpu: 400m + memory: 512Mi + volumeMounts: + - mountPath: /tekton/home/npm + name: npmrc + workingDir: /workspace/source + steps: + - image: gcr.io/jenkinsxio/jx-boot:3.1.155 + name: jx-variables + resources: {} + script: | + #!/usr/bin/env sh + jx gitops variables + - image: node:12-slim + name: build-npm-install + resources: {} + script: | + #!/bin/sh + npm install + - image: node:12-slim + name: build-npm-test + resources: {} + script: | + #!/bin/sh + CI=true DISPLAY=:99 npm test + - image: gcr.io/kaniko-project/executor:debug-v1.3.0 + name: build-container-build + resources: {} + script: | + #!/busybox/sh + source .jx/variables.sh + cp /tekton/creds-secrets/tekton-container-registry-auth/.dockerconfigjson /kaniko/.docker/config.json + /kaniko/executor $KANIKO_FLAGS --context=/workspace/source --dockerfile=Dockerfile --destination=$DOCKER_REGISTRY/$DOCKER_REGISTRY_ORG/$APP_NAME:$VERSION + - image: gcr.io/jenkinsxio/jx-preview:0.0.143 + name: promote-jx-preview + resources: {} + script: | + #!/usr/bin/env sh + source .jx/variables.sh + jx preview create + volumes: + - name: npmrc + secret: + optional: true + secretName: npmrc +status: {} diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-explicit/source.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-explicit/source.yaml new file mode 100644 index 0000000..d7687fa --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-explicit/source.yaml @@ -0,0 +1,20 @@ +apiVersion: tekton.dev/v1beta1 +kind: PipelineRun +metadata: + name: cheese +spec: + pipelineSpec: + tasks: + - name: from-build-pack + taskSpec: + steps: + - image: uses:jenkins-x/jx3-pipeline-catalog/packs/javascript/.lighthouse/jenkins-x/pullrequest.yaml@1d39235ee9235d7d52d4025a8e59cb8bda04306a + name: jx-variables + - image: uses:https://raw.githubusercontent.com/jenkins-x/jx3-pipeline-catalog/1d39235ee9235d7d52d4025a8e59cb8bda04306a/packs/javascript/.lighthouse/jenkins-x/pullrequest.yaml + name: build-npm-install + - image: uses:https://raw.githubusercontent.com/jenkins-x/jx3-pipeline-catalog/1d39235ee9235d7d52d4025a8e59cb8bda04306a/packs/javascript/.lighthouse/jenkins-x/pullrequest.yaml + name: build-npm-test + - image: uses:https://raw.githubusercontent.com/jenkins-x/jx3-pipeline-catalog/1d39235ee9235d7d52d4025a8e59cb8bda04306a/packs/javascript/.lighthouse/jenkins-x/pullrequest.yaml + name: build-container-build + - image: uses:https://raw.githubusercontent.com/jenkins-x/jx3-pipeline-catalog/1d39235ee9235d7d52d4025a8e59cb8bda04306a/packs/javascript/.lighthouse/jenkins-x/pullrequest.yaml + name: promote-jx-preview diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-inherit-sidecar/README.md b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-inherit-sidecar/README.md new file mode 100644 index 0000000..3ae24d0 --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-inherit-sidecar/README.md @@ -0,0 +1,3 @@ +## Reuse steps in a task inherit a sidecar + +This example shows how we can use `image: uses:sourceURI` and a `name: mystep` to include individual the steps in task \ No newline at end of file diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-inherit-sidecar/expected.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-inherit-sidecar/expected.yaml new file mode 100644 index 0000000..ff990c5 --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-inherit-sidecar/expected.yaml @@ -0,0 +1,236 @@ +apiVersion: tekton.dev/v1beta1 +kind: PipelineRun +metadata: + creationTimestamp: null + name: cheese +spec: + params: + - name: BUILD_ID + value: "" + - name: JOB_NAME + value: "" + - name: JOB_SPEC + value: "" + - name: JOB_TYPE + value: "" + - name: PULL_BASE_REF + value: "" + - name: PULL_BASE_SHA + value: "" + - name: PULL_NUMBER + value: "" + - name: PULL_PULL_REF + value: "" + - name: PULL_PULL_SHA + value: "" + - name: PULL_REFS + value: "" + - name: REPO_NAME + value: "" + - name: REPO_OWNER + value: "" + - name: REPO_URL + value: "" + pipelineSpec: + params: + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: '''the kind of job: postsubmit or presubmit''' + name: JOB_TYPE + type: string + - description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + - description: git url to clone + name: REPO_URL + type: string + tasks: + - name: from-build-pack + params: + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + taskSpec: + metadata: {} + params: + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: '''the kind of job: postsubmit or presubmit''' + name: JOB_TYPE + type: string + - description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + - description: git url to clone + name: REPO_URL + type: string + sidecars: + - env: + - name: START_XVFB + value: "false" + image: selenium/standalone-chrome + name: selenium + resources: {} + spec: null + stepTemplate: + env: + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + name: "" + resources: + requests: + cpu: 400m + memory: 512Mi + volumeMounts: + - mountPath: /tekton/home/npm + name: npmrc + workingDir: /workspace/source + steps: + - image: gcr.io/jenkinsxio/jx-boot:3.1.155 + name: jx-variables + resources: {} + script: | + #!/usr/bin/env sh + jx gitops variables + - image: node:12-slim + name: build-npm-install + resources: {} + script: | + #!/bin/sh + npm install + - image: node:12-slim + name: build-npm-test + resources: {} + script: | + #!/bin/sh + CI=true DISPLAY=:99 npm test + - image: gcr.io/kaniko-project/executor:debug-v1.3.0 + name: build-container-build + resources: {} + script: | + #!/busybox/sh + source .jx/variables.sh + cp /tekton/creds-secrets/tekton-container-registry-auth/.dockerconfigjson /kaniko/.docker/config.json + /kaniko/executor $KANIKO_FLAGS --context=/workspace/source --dockerfile=Dockerfile --destination=$DOCKER_REGISTRY/$DOCKER_REGISTRY_ORG/$APP_NAME:$VERSION + - image: gcr.io/jenkinsxio/jx-preview:0.0.143 + name: promote-jx-preview + resources: {} + script: | + #!/usr/bin/env sh + source .jx/variables.sh + jx preview create + volumes: + - name: npmrc + secret: + optional: true + secretName: npmrc +status: {} diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-inherit-sidecar/source.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-inherit-sidecar/source.yaml new file mode 100644 index 0000000..906e9ad --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-inherit-sidecar/source.yaml @@ -0,0 +1,18 @@ +apiVersion: tekton.dev/v1beta1 +kind: PipelineRun +metadata: + name: cheese +spec: + pipelineSpec: + tasks: + - name: from-build-pack + taskSpec: + stepTemplate: + image: uses:jenkins-x/jx3-pipeline-catalog/packs/javascript-selenium/.lighthouse/jenkins-x/pullrequest.yaml@1d39235ee9235d7d52d4025a8e59cb8bda04306a + steps: + - name: jx-variables + - image: uses:https://raw.githubusercontent.com/jenkins-x/jx3-pipeline-catalog/1d39235ee9235d7d52d4025a8e59cb8bda04306a/packs/javascript/.lighthouse/jenkins-x/pullrequest.yaml + name: build-npm-install + - name: build-npm-test + - name: build-container-build + - name: promote-jx-preview diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-multiple-copies/README.md b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-multiple-copies/README.md new file mode 100644 index 0000000..bc10218 --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-multiple-copies/README.md @@ -0,0 +1,3 @@ +## Reuse steps in a task + +This example shows how we can reuse the same step multiple times by using the `name:` syntax of `reuseStepName:uniqueSuffix` \ No newline at end of file diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-multiple-copies/expected.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-multiple-copies/expected.yaml new file mode 100644 index 0000000..3eeb0f7 --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-multiple-copies/expected.yaml @@ -0,0 +1,251 @@ +apiVersion: tekton.dev/v1beta1 +kind: PipelineRun +metadata: + creationTimestamp: null + name: cheese +spec: + params: + - name: BUILD_ID + value: "" + - name: JOB_NAME + value: "" + - name: JOB_SPEC + value: "" + - name: JOB_TYPE + value: "" + - name: PULL_BASE_REF + value: "" + - name: PULL_BASE_SHA + value: "" + - name: PULL_NUMBER + value: "" + - name: PULL_PULL_REF + value: "" + - name: PULL_PULL_SHA + value: "" + - name: PULL_REFS + value: "" + - name: REPO_NAME + value: "" + - name: REPO_OWNER + value: "" + - name: REPO_URL + value: "" + pipelineSpec: + params: + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: '''the kind of job: postsubmit or presubmit''' + name: JOB_TYPE + type: string + - description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + - description: git url to clone + name: REPO_URL + type: string + tasks: + - name: from-build-pack + params: + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + taskSpec: + metadata: {} + params: + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: '''the kind of job: postsubmit or presubmit''' + name: JOB_TYPE + type: string + - description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + - description: git url to clone + name: REPO_URL + type: string + spec: null + stepTemplate: + env: + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + name: "" + resources: + requests: + cpu: 400m + memory: 512Mi + volumeMounts: + - mountPath: /tekton/home/npm + name: npmrc + workingDir: /workspace/source + steps: + - image: gcr.io/jenkinsxio/jx-boot:3.1.155 + name: jx-variables + resources: {} + script: | + #!/usr/bin/env sh + jx gitops variables + - image: node:12-slim + name: build-npm-install + resources: {} + script: | + #!/bin/sh + npm install + - image: node:12-slim + name: build-npm-test + resources: {} + script: | + #!/bin/sh + CI=true DISPLAY=:99 npm test + - image: gcr.io/kaniko-project/executor:debug-v1.3.0 + name: build-container-build + resources: {} + script: | + #!/busybox/sh + source .jx/variables.sh + cp /tekton/creds-secrets/tekton-container-registry-auth/.dockerconfigjson /kaniko/.docker/config.json + /kaniko/executor $KANIKO_FLAGS --context=/workspace/source --dockerfile=Dockerfile --destination=$DOCKER_REGISTRY/$DOCKER_REGISTRY_ORG/$APP_NAME:$VERSION + - env: + - name: IMAGE + value: gcr.io/myproject/myimage + image: gcr.io/kaniko-project/executor:debug-v1.3.0 + name: build-container-build-cheese + resources: {} + script: | + #!/busybox/sh + source .jx/variables.sh + cp /tekton/creds-secrets/tekton-container-registry-auth/.dockerconfigjson /kaniko/.docker/config.json + /kaniko/executor $KANIKO_FLAGS --context=/workspace/source --dockerfile=Dockerfile --destination=$DOCKER_REGISTRY/$DOCKER_REGISTRY_ORG/$APP_NAME:$VERSION + - env: + - name: IMAGE + value: gcr.io/myproject/wine + image: gcr.io/kaniko-project/executor:debug-v1.3.0 + name: build-container-build-wine + resources: {} + script: | + #!/busybox/sh + source .jx/variables.sh + cp /tekton/creds-secrets/tekton-container-registry-auth/.dockerconfigjson /kaniko/.docker/config.json + /kaniko/executor $KANIKO_FLAGS --context=/workspace/source --dockerfile=Dockerfile --destination=$DOCKER_REGISTRY/$DOCKER_REGISTRY_ORG/$APP_NAME:$VERSION + - image: gcr.io/jenkinsxio/jx-preview:0.0.143 + name: promote-jx-preview + resources: {} + script: | + #!/usr/bin/env sh + source .jx/variables.sh + jx preview create + volumes: + - name: npmrc + secret: + optional: true + secretName: npmrc +status: {} diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-multiple-copies/source.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-multiple-copies/source.yaml new file mode 100644 index 0000000..31f93ab --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-multiple-copies/source.yaml @@ -0,0 +1,26 @@ +apiVersion: tekton.dev/v1beta1 +kind: PipelineRun +metadata: + name: cheese +spec: + pipelineSpec: + tasks: + - name: from-build-pack + taskSpec: + stepTemplate: + image: uses:jenkins-x/jx3-pipeline-catalog/packs/javascript/.lighthouse/jenkins-x/pullrequest.yaml@1d39235ee9235d7d52d4025a8e59cb8bda04306a + steps: + - name: jx-variables + - image: uses:https://raw.githubusercontent.com/jenkins-x/jx3-pipeline-catalog/1d39235ee9235d7d52d4025a8e59cb8bda04306a/packs/javascript/.lighthouse/jenkins-x/pullrequest.yaml + name: build-npm-install + - name: build-npm-test + - name: build-container-build + - name: build-container-build:cheese + env: + - name: IMAGE + value: gcr.io/myproject/myimage + - name: build-container-build:wine + env: + - name: IMAGE + value: gcr.io/myproject/wine + - name: promote-jx-preview diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-override-resources/README.md b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-override-resources/README.md new file mode 100644 index 0000000..aa6e357 --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-override-resources/README.md @@ -0,0 +1,3 @@ +## Reuse steps in a task + +This example shows how we can use `image: uses:sourceURI` to reuse all the steps from a task including using reusing shared volume mounts and resource limits on the `stepTemplate` while being able to locally override them \ No newline at end of file diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-override-resources/expected.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-override-resources/expected.yaml new file mode 100644 index 0000000..19b371e --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-override-resources/expected.yaml @@ -0,0 +1,257 @@ +apiVersion: tekton.dev/v1beta1 +kind: PipelineRun +metadata: + creationTimestamp: null + name: cheese +spec: + params: + - name: BUILD_ID + value: "" + - name: JOB_NAME + value: "" + - name: JOB_SPEC + value: "" + - name: JOB_TYPE + value: "" + - name: PULL_BASE_REF + value: "" + - name: PULL_BASE_SHA + value: "" + - name: PULL_NUMBER + value: "" + - name: PULL_PULL_REF + value: "" + - name: PULL_PULL_SHA + value: "" + - name: PULL_REFS + value: "" + - name: REPO_NAME + value: "" + - name: REPO_OWNER + value: "" + - name: REPO_URL + value: "" + pipelineSpec: + params: + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: '''the kind of job: postsubmit or presubmit''' + name: JOB_TYPE + type: string + - description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + - description: git url to clone + name: REPO_URL + type: string + tasks: + - name: from-build-pack + params: + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + taskSpec: + metadata: {} + params: + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: '''the kind of job: postsubmit or presubmit''' + name: JOB_TYPE + type: string + - description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + - description: git url to clone + name: REPO_URL + type: string + spec: null + stepTemplate: + env: + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + name: "" + resources: + requests: + cpu: 600m + memory: 512Mi + volumeMounts: + - mountPath: /tekton/home/npm-something-else + name: npmrc + workingDir: /workspace/my-source + steps: + - image: gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/git-init:v0.19.0 + name: git-clone + resources: {} + script: | + #!/bin/sh + export SUBDIR="source" + echo "git cloning url: $REPO_URL version $PULL_PULL_SHA to dir: $SUBDIR" + git config --global --add user.name ${GIT_AUTHOR_NAME:-jenkins-x-bot} + git config --global --add user.email ${GIT_AUTHOR_EMAIL:-jenkins-x@googlegroups.com} + git config --global credential.helper store + git clone $REPO_URL $SUBDIR + cd $SUBDIR + git checkout $PULL_PULL_SHA + echo "checked out revision: $PULL_PULL_SHA to dir: $SUBDIR" + workingDir: /workspace + - image: gcr.io/jenkinsxio/jx-boot:3.1.62 + name: git-merge + resources: {} + script: | + #!/usr/bin/env sh + jx gitops git merge variables + workingDir: /workspace/source + - image: gcr.io/jenkinsxio/jx-boot:3.1.155 + name: jx-variables + resources: {} + script: | + #!/usr/bin/env sh + jx gitops variables + - image: node:12-slim + name: build-npm-install + resources: {} + script: | + #!/bin/sh + npm install + - image: node:12-slim + name: build-npm-test + resources: {} + script: | + #!/bin/sh + CI=true DISPLAY=:99 npm test + - image: gcr.io/kaniko-project/executor:debug-v1.3.0 + name: build-container-build + resources: {} + script: | + #!/busybox/sh + source .jx/variables.sh + cp /tekton/creds-secrets/tekton-container-registry-auth/.dockerconfigjson /kaniko/.docker/config.json + /kaniko/executor $KANIKO_FLAGS --context=/workspace/source --dockerfile=Dockerfile --destination=$DOCKER_REGISTRY/$DOCKER_REGISTRY_ORG/$APP_NAME:$VERSION + - image: gcr.io/jenkinsxio/jx-preview:0.0.143 + name: promote-jx-preview + resources: {} + script: | + #!/usr/bin/env sh + source .jx/variables.sh + jx preview create + - command: + - jx-updatebot + - pr + image: ghcr.io/jenkins-x/jx-updatebot:0.0.82 + name: promote-release + resources: {} + volumes: + - name: npmrc + secret: + optional: true + secretName: npmrc +status: {} diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-override-resources/source.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-override-resources/source.yaml new file mode 100644 index 0000000..f4bc262 --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-override-resources/source.yaml @@ -0,0 +1,20 @@ +apiVersion: tekton.dev/v1beta1 +kind: PipelineRun +metadata: + name: cheese +spec: + pipelineSpec: + tasks: + - name: from-build-pack + taskSpec: + stepTemplate: + resources: + requests: + cpu: 600m + volumeMounts: + - mountPath: /tekton/home/npm-something-else + name: npmrc + workingDir: /workspace/my-source + steps: + - image: uses:jenkins-x/jx3-pipeline-catalog/packs/javascript/.lighthouse/jenkins-x/pullrequest.yaml@1d39235ee9235d7d52d4025a8e59cb8bda04306a + diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-override-script/README.md b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-override-script/README.md new file mode 100644 index 0000000..1a71ffe --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-override-script/README.md @@ -0,0 +1,8 @@ +## Reuse steps in a task and override them + +This example shows how we can use `image: uses:sourceURI` and a `name: mystep` to include individual the steps in task and then override (add/replace) properties: + +* command to run (either via `script` or `command` and optionally `args`) +* working directory via `workingDir:` +* environment variables via `env:` or `envFrom:` +* volume mounts via `volumeMounts:` \ No newline at end of file diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-override-script/expected.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-override-script/expected.yaml new file mode 100644 index 0000000..c641fa7 --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-override-script/expected.yaml @@ -0,0 +1,236 @@ +apiVersion: tekton.dev/v1beta1 +kind: PipelineRun +metadata: + creationTimestamp: null + name: cheese +spec: + params: + - name: BUILD_ID + value: "" + - name: JOB_NAME + value: "" + - name: JOB_SPEC + value: "" + - name: JOB_TYPE + value: "" + - name: PULL_BASE_REF + value: "" + - name: PULL_BASE_SHA + value: "" + - name: PULL_NUMBER + value: "" + - name: PULL_PULL_REF + value: "" + - name: PULL_PULL_SHA + value: "" + - name: PULL_REFS + value: "" + - name: REPO_NAME + value: "" + - name: REPO_OWNER + value: "" + - name: REPO_URL + value: "" + pipelineSpec: + params: + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: '''the kind of job: postsubmit or presubmit''' + name: JOB_TYPE + type: string + - description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + - description: git url to clone + name: REPO_URL + type: string + tasks: + - name: from-build-pack + params: + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + taskSpec: + metadata: {} + params: + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: '''the kind of job: postsubmit or presubmit''' + name: JOB_TYPE + type: string + - description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + - description: git url to clone + name: REPO_URL + type: string + spec: null + stepTemplate: + env: + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + name: "" + resources: + requests: + cpu: 400m + memory: 512Mi + volumeMounts: + - mountPath: /tekton/home/npm + name: npmrc + workingDir: /workspace/source + steps: + - image: gcr.io/jenkinsxio/jx-boot:3.1.155 + name: jx-variables + resources: {} + script: | + #!/usr/bin/env sh + jx gitops variables + - image: node:12-slim + name: build-npm-install + resources: {} + script: | + #!/bin/sh + npm install + - image: node:12-slim + name: build-npm-test + resources: {} + script: | + #!/bin/sh + CI=true DISPLAY=:99 npm test + - image: gcr.io/kaniko-project/executor:debug-v1.3.0 + name: build-container-build + resources: {} + script: | + #!/busybox/sh + source .jx/variables.sh + cp /tekton/creds-secrets/tekton-container-registry-auth/.dockerconfigjson /kaniko/.docker/config.json + /kaniko/executor $KANIKO_FLAGS --context=/workspace/source --dockerfile=Dockerfile --destination=$DOCKER_REGISTRY/$DOCKER_REGISTRY_ORG/$APP_NAME:$VERSION + - image: gcr.io/jenkinsxio/jx-preview:0.0.143 + name: promote-jx-preview + resources: {} + script: | + #!/usr/bin/env sh + source .jx/variables.sh + jx preview create + - image: ghcr.io/jenkins-x/jx-updatebot:0.0.82 + name: promote-release + resources: {} + script: | + #!/usr/bin/env sh + source .jx/variables.sh + jx updatebot argo promote --target-git-url https://github.com/myorg/my-staging-repo + volumes: + - name: npmrc + secret: + optional: true + secretName: npmrc +status: {} diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-override-script/source.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-override-script/source.yaml new file mode 100644 index 0000000..27f9efb --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-override-script/source.yaml @@ -0,0 +1,24 @@ +apiVersion: tekton.dev/v1beta1 +kind: PipelineRun +metadata: + name: cheese +spec: + pipelineSpec: + tasks: + - name: from-build-pack + taskSpec: + stepTemplate: + image: uses:jenkins-x/jx3-pipeline-catalog/packs/javascript/.lighthouse/jenkins-x/pullrequest.yaml@1d39235ee9235d7d52d4025a8e59cb8bda04306a + steps: + - name: jx-variables + - image: uses:https://raw.githubusercontent.com/jenkins-x/jx3-pipeline-catalog/1d39235ee9235d7d52d4025a8e59cb8bda04306a/packs/javascript/.lighthouse/jenkins-x/pullrequest.yaml + name: build-npm-install + - name: build-npm-test + - name: build-container-build + - name: promote-jx-preview + - name: promote-release + script: | + #!/usr/bin/env sh + source .jx/variables.sh + jx updatebot argo promote --target-git-url https://github.com/myorg/my-staging-repo + diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-override/README.md b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-override/README.md new file mode 100644 index 0000000..1a71ffe --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-override/README.md @@ -0,0 +1,8 @@ +## Reuse steps in a task and override them + +This example shows how we can use `image: uses:sourceURI` and a `name: mystep` to include individual the steps in task and then override (add/replace) properties: + +* command to run (either via `script` or `command` and optionally `args`) +* working directory via `workingDir:` +* environment variables via `env:` or `envFrom:` +* volume mounts via `volumeMounts:` \ No newline at end of file diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-override/expected.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-override/expected.yaml new file mode 100644 index 0000000..af1f159 --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-override/expected.yaml @@ -0,0 +1,232 @@ +apiVersion: tekton.dev/v1beta1 +kind: PipelineRun +metadata: + creationTimestamp: null + name: cheese +spec: + params: + - name: BUILD_ID + value: "" + - name: JOB_NAME + value: "" + - name: JOB_SPEC + value: "" + - name: JOB_TYPE + value: "" + - name: PULL_BASE_REF + value: "" + - name: PULL_BASE_SHA + value: "" + - name: PULL_NUMBER + value: "" + - name: PULL_PULL_REF + value: "" + - name: PULL_PULL_SHA + value: "" + - name: PULL_REFS + value: "" + - name: REPO_NAME + value: "" + - name: REPO_OWNER + value: "" + - name: REPO_URL + value: "" + pipelineSpec: + params: + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: '''the kind of job: postsubmit or presubmit''' + name: JOB_TYPE + type: string + - description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + - description: git url to clone + name: REPO_URL + type: string + tasks: + - name: from-build-pack + params: + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + taskSpec: + metadata: {} + params: + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: '''the kind of job: postsubmit or presubmit''' + name: JOB_TYPE + type: string + - description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + - description: git url to clone + name: REPO_URL + type: string + spec: null + stepTemplate: + env: + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + name: "" + resources: + requests: + cpu: 400m + memory: 512Mi + workingDir: /workspace/source + steps: + - env: + - name: MY_NEW_ENV_VAR + value: this-is-a-new-value + image: gcr.io/jenkinsxio/jx-boot:3.1.155 + name: jx-variables + resources: {} + script: | + #!/usr/bin/env sh + jx gitops variables + - envFrom: + - configMapRef: + name: myconfigmap + optional: true + image: node:12-slim + name: build-npm-install + resources: {} + script: | + #!/bin/sh + npm install + - image: node:12-slim + name: build-npm-test + resources: {} + script: | + #!/usr/bin/env sh + echo "this is my custom script" + workingDir: /workspace/mynewdir + - args: + - -c + - echo this is a new custom command + command: + - bash + image: gcr.io/kaniko-project/executor:debug-v1.3.0 + name: build-container-build + resources: {} + - image: gcr.io/jenkinsxio/jx-preview:0.0.143 + name: promote-jx-preview + resources: {} + script: | + #!/usr/bin/env sh + source .jx/variables.sh + jx preview create + volumeMounts: + - mountPath: /foo/bar + name: my-new-volume +status: {} diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-override/source.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-override/source.yaml new file mode 100644 index 0000000..e25a0e6 --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-override/source.yaml @@ -0,0 +1,39 @@ +apiVersion: tekton.dev/v1beta1 +kind: PipelineRun +metadata: + name: cheese +spec: + pipelineSpec: + tasks: + - name: from-build-pack + taskSpec: + steps: + - image: uses:https://raw.githubusercontent.com/jenkins-x/jx3-pipeline-catalog/1d39235ee9235d7d52d4025a8e59cb8bda04306a/packs/javascript/.lighthouse/jenkins-x/pullrequest.yaml + name: jx-variables + env: + - name: MY_NEW_ENV_VAR + value: this-is-a-new-value + - image: uses:https://raw.githubusercontent.com/jenkins-x/jx3-pipeline-catalog/1d39235ee9235d7d52d4025a8e59cb8bda04306a/packs/javascript/.lighthouse/jenkins-x/pullrequest.yaml + name: build-npm-install + envFrom: + - configMapRef: + name: myconfigmap + optional: true + - image: uses:https://raw.githubusercontent.com/jenkins-x/jx3-pipeline-catalog/1d39235ee9235d7d52d4025a8e59cb8bda04306a/packs/javascript/.lighthouse/jenkins-x/pullrequest.yaml + name: build-npm-test + script: | + #!/usr/bin/env sh + echo "this is my custom script" + workingDir: /workspace/mynewdir + - image: uses:https://raw.githubusercontent.com/jenkins-x/jx3-pipeline-catalog/1d39235ee9235d7d52d4025a8e59cb8bda04306a/packs/javascript/.lighthouse/jenkins-x/pullrequest.yaml + name: build-container-build + command: + - bash + args: + - -c + - "echo this is a new custom command" + - image: uses:https://raw.githubusercontent.com/jenkins-x/jx3-pipeline-catalog/1d39235ee9235d7d52d4025a8e59cb8bda04306a/packs/javascript/.lighthouse/jenkins-x/pullrequest.yaml + name: promote-jx-preview + volumeMounts: + - mountPath: /foo/bar + name: my-new-volume diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-version-stream/README.md b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-version-stream/README.md new file mode 100644 index 0000000..f7a7a71 --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-version-stream/README.md @@ -0,0 +1,3 @@ +## Reuse steps in a task + +This example shows how we can use `image: uses:sourceURI` and a `name: mystep` to include individual the steps in task - and using the `@versionStream` which is resolved with the version stream to find the actual git tag to use. \ No newline at end of file diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-version-stream/expected.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-version-stream/expected.yaml new file mode 100644 index 0000000..57e0343 --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-version-stream/expected.yaml @@ -0,0 +1,221 @@ +apiVersion: tekton.dev/v1beta1 +kind: PipelineRun +metadata: + creationTimestamp: null + name: cheese +spec: + params: + - name: BUILD_ID + value: "" + - name: JOB_NAME + value: "" + - name: JOB_SPEC + value: "" + - name: JOB_TYPE + value: "" + - name: PULL_BASE_REF + value: "" + - name: PULL_BASE_SHA + value: "" + - name: PULL_NUMBER + value: "" + - name: PULL_PULL_REF + value: "" + - name: PULL_PULL_SHA + value: "" + - name: PULL_REFS + value: "" + - name: REPO_NAME + value: "" + - name: REPO_OWNER + value: "" + - name: REPO_URL + value: "" + pipelineSpec: + params: + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: '''the kind of job: postsubmit or presubmit''' + name: JOB_TYPE + type: string + - description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + - description: git url to clone + name: REPO_URL + type: string + tasks: + - name: from-build-pack + params: + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + taskSpec: + metadata: {} + params: + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: '''the kind of job: postsubmit or presubmit''' + name: JOB_TYPE + type: string + - description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + - description: git url to clone + name: REPO_URL + type: string + spec: null + stepTemplate: + env: + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + name: "" + resources: + requests: + cpu: 400m + memory: 512Mi + workingDir: /workspace/source + steps: + - image: gcr.io/jenkinsxio/jx-boot:latest + name: jx-variables + resources: {} + script: | + #!/usr/bin/env sh + jx gitops variables + - image: node:12-slim + name: build-npm-install + resources: {} + script: | + #!/bin/sh + npm install + - image: node:12-slim + name: build-npm-test + resources: {} + script: | + #!/bin/sh + CI=true DISPLAY=:99 npm test + - image: gcr.io/kaniko-project/executor:debug-v1.3.0 + name: build-container-build + resources: {} + script: | + #!/busybox/sh + source .jx/variables.sh + cp /tekton/creds-secrets/tekton-container-registry-auth/.dockerconfigjson /kaniko/.docker/config.json + /kaniko/executor $KANIKO_FLAGS --context=/workspace/source --dockerfile=Dockerfile --destination=$DOCKER_REGISTRY/$DOCKER_REGISTRY_ORG/$APP_NAME:$VERSION + - image: gcr.io/jenkinsxio/jx-preview:0.0.143 + name: promote-jx-preview + resources: {} + script: | + #!/usr/bin/env sh + source .jx/variables.sh + jx preview create +status: {} diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-version-stream/source.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-version-stream/source.yaml new file mode 100644 index 0000000..6b9d720 --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-version-stream/source.yaml @@ -0,0 +1,17 @@ +apiVersion: tekton.dev/v1beta1 +kind: PipelineRun +metadata: + name: cheese +spec: + pipelineSpec: + tasks: + - name: from-build-pack + taskSpec: + stepTemplate: + image: uses:jenkins-x/jx3-pipeline-catalog/packs/javascript/.lighthouse/jenkins-x/pullrequest.yaml@versionStream + steps: + - name: jx-variables + - name: build-npm-install + - name: build-npm-test + - name: build-container-build + - name: promote-jx-preview diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-with-sidecar-ws/README.md b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-with-sidecar-ws/README.md new file mode 100644 index 0000000..ccb108f --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-with-sidecar-ws/README.md @@ -0,0 +1,3 @@ +## Reuse steps in a task with sidecars and workspaces + +This requires alpha support to pass validation \ No newline at end of file diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-with-sidecar-ws/expected.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-with-sidecar-ws/expected.yaml new file mode 100644 index 0000000..8c35216 --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-with-sidecar-ws/expected.yaml @@ -0,0 +1,264 @@ +apiVersion: tekton.dev/v1beta1 +kind: PipelineRun +metadata: + creationTimestamp: null + name: pullrequest +spec: + params: + - name: BUILD_ID + value: "" + - name: JOB_NAME + value: "" + - name: JOB_SPEC + value: "" + - name: JOB_TYPE + value: "" + - name: PULL_BASE_REF + value: "" + - name: PULL_BASE_SHA + value: "" + - name: PULL_NUMBER + value: "" + - name: PULL_PULL_REF + value: "" + - name: PULL_PULL_SHA + value: "" + - name: PULL_REFS + value: "" + - name: REPO_NAME + value: "" + - name: REPO_OWNER + value: "" + - name: REPO_URL + value: "" + pipelineSpec: + params: + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: '''the kind of job: postsubmit or presubmit''' + name: JOB_TYPE + type: string + - description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + - description: git url to clone + name: REPO_URL + type: string + tasks: + - name: from-build-pack + params: + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + resources: {} + taskSpec: + metadata: {} + params: + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: '''the kind of job: postsubmit or presubmit''' + name: JOB_TYPE + type: string + - description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + - description: git url to clone + name: REPO_URL + type: string + sidecars: + - image: xyz/json-server:0.1.15 + name: json-server + resources: {} + script: | + #!/bin/ash + while [ ! -f /workspace/source/JsonServer/mocks.json ] ; do + echo "Waiting for mocks.json" + sleep 1 + done + json-server --watch /workspace/source/JsonServer/mocks.json + workspaces: + - mountPath: "" + name: source + spec: null + stepTemplate: + env: + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + name: "" + resources: + requests: + cpu: 400m + memory: 512Mi + volumeMounts: + - mountPath: /tekton/home/npm + name: npmrc + workingDir: /workspace/source + steps: + - image: gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/git-init:v0.19.0 + name: git-clone + resources: {} + script: | + #!/bin/sh + export SUBDIR="source" + echo "git cloning url: $REPO_URL version $PULL_BASE_SHA to dir: $SUBDIR" + git config --global --add user.name ${GIT_AUTHOR_NAME:-jenkins-x-bot} + git config --global --add user.email ${GIT_AUTHOR_EMAIL:-jenkins-x@googlegroups.com} + git config --global credential.helper store + git clone $REPO_URL $SUBDIR + cd $SUBDIR + git checkout $PULL_BASE_SHA + echo "checked out revision: $PULL_BASE_SHA to dir: $SUBDIR" + workingDir: /workspace + - image: gcr.io/jenkinsxio/jx-boot:3.1.155 + name: jx-variables + resources: {} + script: | + #!/usr/bin/env sh + jx gitops variables + - image: node:14-slim + name: "" + resources: {} + - image: node:12-slim + name: build-npm-test + resources: {} + script: | + #!/bin/sh + yarn install + CI=true DISPLAY=:99 yarn run test:unit + volumes: + - name: npmrc + secret: + optional: true + secretName: npmrc + workspaces: + - description: The git repo will be cloned onto the volume backing this workspace + mountPath: /workspace + name: output + - name: source + workspaces: + - name: source + workspace: source + - name: output + workspace: output + workspaces: + - name: source + - description: The git repo will be cloned onto the volume backing this workspace + name: output + podTemplate: {} + serviceAccountName: tekton-bot + timeout: 12h0m0s + workspaces: + - emptyDir: {} + name: source + - emptyDir: {} + name: output +status: {} diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-with-sidecar-ws/source.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-with-sidecar-ws/source.yaml new file mode 100644 index 0000000..ebc4086 --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-with-sidecar-ws/source.yaml @@ -0,0 +1,58 @@ +apiVersion: tekton.dev/v1beta1 +kind: PipelineRun +metadata: + creationTimestamp: null + name: pullrequest +spec: + pipelineSpec: + tasks: + - name: from-build-pack + resources: {} + taskSpec: + metadata: {} + sidecars: + - image: xyz/json-server:0.1.15 + name: "json-server" + resources: {} + script: | + #!/bin/ash + while [ ! -f /workspace/source/JsonServer/mocks.json ] ; do + echo "Waiting for mocks.json" + sleep 1 + done + json-server --watch /workspace/source/JsonServer/mocks.json + workspaces: + - name: source + stepTemplate: + image: uses:jenkins-x/jx3-pipeline-catalog/packs/javascript/.lighthouse/jenkins-x/pullrequest.yaml@1d39235ee9235d7d52d4025a8e59cb8bda04306a + name: "" + resources: + requests: + cpu: 400m + memory: 512Mi + steps: + - image: uses:jenkins-x/jx3-pipeline-catalog/tasks/git-clone/git-clone.yaml@versionStream + name: "" + resources: {} + - name: jx-variables + resources: {} + - image: node:14-slim + - name: build-npm-test + resources: {} + script: | + #!/bin/sh + yarn install + CI=true DISPLAY=:99 yarn run test:unit + workspaces: + - name: source + workspaces: + - name: source + workspace: source + workspaces: + - name: source + podTemplate: {} + workspaces: + - {name: source, emptyDir: {}} + serviceAccountName: tekton-bot + timeout: 12h0m0s +status: {} \ No newline at end of file diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-with-sidecar/README.md b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-with-sidecar/README.md new file mode 100644 index 0000000..38d8f52 --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-with-sidecar/README.md @@ -0,0 +1,3 @@ +## Reuse steps in a task with sidecars + +This example shows how we can use `image: uses:sourceURI` and a `name: mystep` to include individual the steps in task \ No newline at end of file diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-with-sidecar/expected.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-with-sidecar/expected.yaml new file mode 100644 index 0000000..ff990c5 --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-with-sidecar/expected.yaml @@ -0,0 +1,236 @@ +apiVersion: tekton.dev/v1beta1 +kind: PipelineRun +metadata: + creationTimestamp: null + name: cheese +spec: + params: + - name: BUILD_ID + value: "" + - name: JOB_NAME + value: "" + - name: JOB_SPEC + value: "" + - name: JOB_TYPE + value: "" + - name: PULL_BASE_REF + value: "" + - name: PULL_BASE_SHA + value: "" + - name: PULL_NUMBER + value: "" + - name: PULL_PULL_REF + value: "" + - name: PULL_PULL_SHA + value: "" + - name: PULL_REFS + value: "" + - name: REPO_NAME + value: "" + - name: REPO_OWNER + value: "" + - name: REPO_URL + value: "" + pipelineSpec: + params: + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: '''the kind of job: postsubmit or presubmit''' + name: JOB_TYPE + type: string + - description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + - description: git url to clone + name: REPO_URL + type: string + tasks: + - name: from-build-pack + params: + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + taskSpec: + metadata: {} + params: + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: '''the kind of job: postsubmit or presubmit''' + name: JOB_TYPE + type: string + - description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + - description: git url to clone + name: REPO_URL + type: string + sidecars: + - env: + - name: START_XVFB + value: "false" + image: selenium/standalone-chrome + name: selenium + resources: {} + spec: null + stepTemplate: + env: + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + name: "" + resources: + requests: + cpu: 400m + memory: 512Mi + volumeMounts: + - mountPath: /tekton/home/npm + name: npmrc + workingDir: /workspace/source + steps: + - image: gcr.io/jenkinsxio/jx-boot:3.1.155 + name: jx-variables + resources: {} + script: | + #!/usr/bin/env sh + jx gitops variables + - image: node:12-slim + name: build-npm-install + resources: {} + script: | + #!/bin/sh + npm install + - image: node:12-slim + name: build-npm-test + resources: {} + script: | + #!/bin/sh + CI=true DISPLAY=:99 npm test + - image: gcr.io/kaniko-project/executor:debug-v1.3.0 + name: build-container-build + resources: {} + script: | + #!/busybox/sh + source .jx/variables.sh + cp /tekton/creds-secrets/tekton-container-registry-auth/.dockerconfigjson /kaniko/.docker/config.json + /kaniko/executor $KANIKO_FLAGS --context=/workspace/source --dockerfile=Dockerfile --destination=$DOCKER_REGISTRY/$DOCKER_REGISTRY_ORG/$APP_NAME:$VERSION + - image: gcr.io/jenkinsxio/jx-preview:0.0.143 + name: promote-jx-preview + resources: {} + script: | + #!/usr/bin/env sh + source .jx/variables.sh + jx preview create + volumes: + - name: npmrc + secret: + optional: true + secretName: npmrc +status: {} diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-with-sidecar/source.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-with-sidecar/source.yaml new file mode 100644 index 0000000..85f386a --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps-with-sidecar/source.yaml @@ -0,0 +1,24 @@ +apiVersion: tekton.dev/v1beta1 +kind: PipelineRun +metadata: + name: cheese +spec: + pipelineSpec: + tasks: + - name: from-build-pack + taskSpec: + stepTemplate: + image: uses:jenkins-x/jx3-pipeline-catalog/packs/javascript/.lighthouse/jenkins-x/pullrequest.yaml@1d39235ee9235d7d52d4025a8e59cb8bda04306a + steps: + - name: jx-variables + - image: uses:https://raw.githubusercontent.com/jenkins-x/jx3-pipeline-catalog/1d39235ee9235d7d52d4025a8e59cb8bda04306a/packs/javascript/.lighthouse/jenkins-x/pullrequest.yaml + name: build-npm-install + - name: build-npm-test + - name: build-container-build + - name: promote-jx-preview + sidecars: + - image: selenium/standalone-chrome + name: selenium + env: + - name: START_XVFB + value: 'false' diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps/README.md b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps/README.md new file mode 100644 index 0000000..ea1fcbf --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps/README.md @@ -0,0 +1,3 @@ +## Reuse steps in a task + +This example shows how we can use `image: uses:sourceURI` and a `name: mystep` to include individual the steps in task \ No newline at end of file diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps/expected.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps/expected.yaml new file mode 100644 index 0000000..c5edf08 --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps/expected.yaml @@ -0,0 +1,229 @@ +apiVersion: tekton.dev/v1beta1 +kind: PipelineRun +metadata: + creationTimestamp: null + name: cheese +spec: + params: + - name: BUILD_ID + value: "" + - name: JOB_NAME + value: "" + - name: JOB_SPEC + value: "" + - name: JOB_TYPE + value: "" + - name: PULL_BASE_REF + value: "" + - name: PULL_BASE_SHA + value: "" + - name: PULL_NUMBER + value: "" + - name: PULL_PULL_REF + value: "" + - name: PULL_PULL_SHA + value: "" + - name: PULL_REFS + value: "" + - name: REPO_NAME + value: "" + - name: REPO_OWNER + value: "" + - name: REPO_URL + value: "" + pipelineSpec: + params: + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: '''the kind of job: postsubmit or presubmit''' + name: JOB_TYPE + type: string + - description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + - description: git url to clone + name: REPO_URL + type: string + tasks: + - name: from-build-pack + params: + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + taskSpec: + metadata: {} + params: + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: '''the kind of job: postsubmit or presubmit''' + name: JOB_TYPE + type: string + - description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + - description: git url to clone + name: REPO_URL + type: string + spec: null + stepTemplate: + env: + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + name: "" + resources: + requests: + cpu: 400m + memory: 512Mi + volumeMounts: + - mountPath: /tekton/home/npm + name: npmrc + workingDir: /workspace/source + steps: + - image: gcr.io/jenkinsxio/jx-boot:3.1.155 + name: jx-variables + resources: {} + script: | + #!/usr/bin/env sh + jx gitops variables + - image: node:12-slim + name: build-npm-install + resources: {} + script: | + #!/bin/sh + npm install + - image: node:12-slim + name: build-npm-test + resources: {} + script: | + #!/bin/sh + CI=true DISPLAY=:99 npm test + - image: gcr.io/kaniko-project/executor:debug-v1.3.0 + name: build-container-build + resources: {} + script: | + #!/busybox/sh + source .jx/variables.sh + cp /tekton/creds-secrets/tekton-container-registry-auth/.dockerconfigjson /kaniko/.docker/config.json + /kaniko/executor $KANIKO_FLAGS --context=/workspace/source --dockerfile=Dockerfile --destination=$DOCKER_REGISTRY/$DOCKER_REGISTRY_ORG/$APP_NAME:$VERSION + - image: gcr.io/jenkinsxio/jx-preview:0.0.143 + name: promote-jx-preview + resources: {} + script: | + #!/usr/bin/env sh + source .jx/variables.sh + jx preview create + volumes: + - name: npmrc + secret: + optional: true + secretName: npmrc +status: {} diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps/source.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps/source.yaml new file mode 100644 index 0000000..8ab2be2 --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-steps/source.yaml @@ -0,0 +1,18 @@ +apiVersion: tekton.dev/v1beta1 +kind: PipelineRun +metadata: + name: cheese +spec: + pipelineSpec: + tasks: + - name: from-build-pack + taskSpec: + stepTemplate: + image: uses:jenkins-x/jx3-pipeline-catalog/packs/javascript/.lighthouse/jenkins-x/pullrequest.yaml@1d39235ee9235d7d52d4025a8e59cb8bda04306a + steps: + - name: jx-variables + - image: uses:https://raw.githubusercontent.com/jenkins-x/jx3-pipeline-catalog/1d39235ee9235d7d52d4025a8e59cb8bda04306a/packs/javascript/.lighthouse/jenkins-x/pullrequest.yaml + name: build-npm-install + - name: build-npm-test + - name: build-container-build + - name: promote-jx-preview diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-task-and-steps/README.md b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-task-and-steps/README.md new file mode 100644 index 0000000..ea1fcbf --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-task-and-steps/README.md @@ -0,0 +1,3 @@ +## Reuse steps in a task + +This example shows how we can use `image: uses:sourceURI` and a `name: mystep` to include individual the steps in task \ No newline at end of file diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-task-and-steps/expected.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-task-and-steps/expected.yaml new file mode 100644 index 0000000..0b950a7 --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-task-and-steps/expected.yaml @@ -0,0 +1,307 @@ +apiVersion: tekton.dev/v1beta1 +kind: PipelineRun +metadata: + creationTimestamp: null + name: release +spec: + params: + - name: BUILD_ID + value: "" + - name: JOB_NAME + value: "" + - name: JOB_SPEC + value: "" + - name: JOB_TYPE + value: "" + - name: PULL_BASE_REF + value: "" + - name: PULL_BASE_SHA + value: "" + - name: PULL_NUMBER + value: "" + - name: PULL_PULL_REF + value: "" + - name: PULL_PULL_SHA + value: "" + - name: PULL_REFS + value: "" + - name: REPO_NAME + value: "" + - name: REPO_OWNER + value: "" + - name: REPO_URL + value: "" + pipelineSpec: + params: + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: '''the kind of job: postsubmit or presubmit''' + name: JOB_TYPE + type: string + - description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + - description: git url to clone + name: REPO_URL + type: string + tasks: + - name: from-build-pack + params: + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + resources: {} + taskSpec: + metadata: {} + params: + - description: the unique build number + name: BUILD_ID + type: string + - description: the name of the job which is the trigger context name + name: JOB_NAME + type: string + - description: the specification of the job + name: JOB_SPEC + type: string + - description: '''the kind of job: postsubmit or presubmit''' + name: JOB_TYPE + type: string + - description: the base git reference of the pull request + name: PULL_BASE_REF + type: string + - description: the git sha of the base of the pull request + name: PULL_BASE_SHA + type: string + - default: "" + description: git pull request number + name: PULL_NUMBER + type: string + - default: "" + description: git pull request ref in the form 'refs/pull/$PULL_NUMBER/head' + name: PULL_PULL_REF + type: string + - default: "" + description: git revision to checkout (branch, tag, sha, ref…) + name: PULL_PULL_SHA + type: string + - description: git pull reference strings of base and latest in the form 'master:$PULL_BASE_SHA,$PULL_NUMBER:$PULL_PULL_SHA:refs/pull/$PULL_NUMBER/head' + name: PULL_REFS + type: string + - description: git repository name + name: REPO_NAME + type: string + - description: git repository owner (user or organisation) + name: REPO_OWNER + type: string + - description: git url to clone + name: REPO_URL + type: string + spec: null + stepTemplate: + env: + - name: _JAVA_OPTIONS + value: -XX:+UnlockExperimentalVMOptions -Dsun.zip.disableMemoryMapping=true + -XX:+UseParallelGC -XX:MinHeapFreeRatio=5 -XX:MaxHeapFreeRatio=10 -XX:GCTimeRatio=4 + -XX:AdaptiveSizePolicyWeight=90 -Xms10m -Xmx192m + - name: MAVEN_OPTS + value: -Dhttp.keepAlive=false -Dmaven.wagon.http.pool=false -Dmaven.wagon.httpconnectionManager.ttlSeconds=25 + -Dmaven.wagon.http.retryHandler.count=3 + - name: BUILD_ID + value: $(params.BUILD_ID) + - name: JOB_NAME + value: $(params.JOB_NAME) + - name: JOB_SPEC + value: $(params.JOB_SPEC) + - name: JOB_TYPE + value: $(params.JOB_TYPE) + - name: PULL_BASE_REF + value: $(params.PULL_BASE_REF) + - name: PULL_BASE_SHA + value: $(params.PULL_BASE_SHA) + - name: PULL_NUMBER + value: $(params.PULL_NUMBER) + - name: PULL_PULL_REF + value: $(params.PULL_PULL_REF) + - name: PULL_PULL_SHA + value: $(params.PULL_PULL_SHA) + - name: PULL_REFS + value: $(params.PULL_REFS) + - name: REPO_NAME + value: $(params.REPO_NAME) + - name: REPO_OWNER + value: $(params.REPO_OWNER) + - name: REPO_URL + value: $(params.REPO_URL) + name: "" + resources: + requests: + cpu: 400m + memory: 512Mi + volumeMounts: + - mountPath: /root/.m2/ + name: maven-settings + - mountPath: /root/.gnupg + name: release-gpg + workingDir: /workspace/source + steps: + - image: gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/git-init:v0.19.0 + name: git-clone + resources: {} + script: | + #!/bin/sh + export SUBDIR="source" + echo "git cloning url: $REPO_URL version $PULL_BASE_SHA to dir: $SUBDIR" + git config --global --add user.name ${GIT_AUTHOR_NAME:-jenkins-x-bot} + git config --global --add user.email ${GIT_AUTHOR_EMAIL:-jenkins-x@googlegroups.com} + git config --global credential.helper store + git clone $REPO_URL $SUBDIR + cd $SUBDIR + git checkout $PULL_BASE_SHA + echo "checked out revision: $PULL_BASE_SHA to dir: $SUBDIR" + workingDir: /workspace + - image: gcr.io/jenkinsxio/jx-release-version:2.2.5 + name: next-version + resources: {} + script: | + #!/usr/bin/env sh + jx-release-version > VERSION + - image: ghcr.io/jenkins-x/jx-boot:3.1.335 + name: jx-variables + resources: {} + script: | + #!/usr/bin/env sh + jx gitops variables + - image: maven:3.6-openjdk-11 + name: build-mvn-deploy + resources: {} + script: | + #!/usr/bin/env bash + source .jx/variables.sh + + # modify the pom.xml + echo "upgrading the pom to version $VERSION" + mvn versions:set -DnewVersion=$VERSION + + mvn --no-transfer-progress clean deploy + - image: gcr.io/jenkinsxio/jx-registry:0.0.11 + name: check-registry + resources: {} + - image: gcr.io/kaniko-project/executor:debug-v1.3.0 + name: build-container-build + resources: {} + script: | + #!/busybox/sh + source .jx/variables.sh + cp /tekton/creds-secrets/tekton-container-registry-auth/.dockerconfigjson /kaniko/.docker/config.json + /kaniko/executor $KANIKO_FLAGS --context=/workspace/source --dockerfile=Dockerfile --destination=$PUSH_CONTAINER_REGISTRY/$DOCKER_REGISTRY_ORG/$APP_NAME:$VERSION + - image: gcr.io/jenkinsxio/jx-changelog:0.0.34 + name: promote-changelog + resources: {} + script: | + #!/usr/bin/env sh + source .jx/variables.sh + + if [ -d "charts/$REPO_NAME" ]; then + sed -i -e "s/^version:.*/version: $VERSION/" ./charts/$REPO_NAME/Chart.yaml + sed -i -e "s/repository:.*/repository: $DOCKER_REGISTRY\/$DOCKER_REGISTRY_ORG\/$APP_NAME/" ./charts/$REPO_NAME/values.yaml + sed -i -e "s/tag:.*/tag: $VERSION/" ./charts/$REPO_NAME/values.yaml; + else echo no charts; fi + + jx changelog create --version v${VERSION} + + git add * || true + git commit -a -m "chore: release $VERSION" --allow-empty + git tag -fa v$VERSION -m "Release version $VERSION" + git push --force origin v$VERSION + - image: ghcr.io/jenkins-x/jx-boot:3.1.335 + name: promote-helm-release + resources: {} + script: | + #!/usr/bin/env sh + jx gitops helm release + - image: ghcr.io/jenkins-x/jx-promote:0.0.243 + name: promote-jx-promote + resources: {} + script: | + #!/usr/bin/env sh + source .jx/variables.sh + jx promote -b --all --timeout 1h --no-poll + volumes: + - name: maven-settings + secret: + secretName: jenkins-maven-settings + - name: release-gpg + secret: + optional: true + secretName: jenkins-release-gpg + workspaces: + - description: The git repo will be cloned onto the volume backing this workspace + mountPath: /workspace + name: output + workspaces: + - name: output + workspace: output + workspaces: + - description: The git repo will be cloned onto the volume backing this workspace + name: output + podTemplate: {} + serviceAccountName: tekton-bot + timeout: 240h0m0s + workspaces: + - emptyDir: {} + name: output +status: {} diff --git a/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-task-and-steps/source.yaml b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-task-and-steps/source.yaml new file mode 100644 index 0000000..ac34380 --- /dev/null +++ b/pkg/triggerconfig/inrepo/test_data/load_pipelinerun/uses-task-and-steps/source.yaml @@ -0,0 +1,64 @@ +apiVersion: tekton.dev/v1beta1 +kind: PipelineRun +metadata: + creationTimestamp: null + name: release +spec: + pipelineSpec: + tasks: + - name: from-build-pack + resources: {} + taskSpec: + metadata: {} + stepTemplate: + env: + - name: _JAVA_OPTIONS + value: -XX:+UnlockExperimentalVMOptions -Dsun.zip.disableMemoryMapping=true + -XX:+UseParallelGC -XX:MinHeapFreeRatio=5 -XX:MaxHeapFreeRatio=10 -XX:GCTimeRatio=4 + -XX:AdaptiveSizePolicyWeight=90 -Xms10m -Xmx192m + - name: MAVEN_OPTS + value: -Dhttp.keepAlive=false -Dmaven.wagon.http.pool=false -Dmaven.wagon.httpconnectionManager.ttlSeconds=25 -Dmaven.wagon.http.retryHandler.count=3 + image: uses:jenkins-x/jx3-pipeline-catalog/tasks/maven-java11/release.yaml@versionStream + name: "" + resources: + requests: + cpu: 400m + memory: 512Mi + volumeMounts: + - mountPath: /root/.m2/ + name: maven-settings + - mountPath: /root/.gnupg + name: release-gpg + workingDir: /workspace/source + steps: + - image: uses:jenkins-x/jx3-pipeline-catalog/tasks/git-clone/git-clone.yaml@versionStream + name: "" + resources: {} + - name: next-version + resources: {} + - name: jx-variables + resources: {} + - name: build-mvn-deploy + resources: {} + - name: check-registry + resources: {} + - name: build-container-build + resources: {} + - name: promote-changelog + resources: {} + - name: promote-helm-release + resources: {} + - name: promote-jx-promote + resources: {} + volumes: + - name: maven-settings + secret: + secretName: jenkins-maven-settings + - name: release-gpg + secret: + optional: true + secretName: jenkins-release-gpg + podTemplate: {} + serviceAccountName: tekton-bot + timeout: 240h0m0s +status: {} \ No newline at end of file diff --git a/pkg/triggerconfig/inrepo/test_data/load_url/foo.yaml b/pkg/triggerconfig/inrepo/test_data/load_url/foo.yaml index 6f15c7b..22da2d4 100644 --- a/pkg/triggerconfig/inrepo/test_data/load_url/foo.yaml +++ b/pkg/triggerconfig/inrepo/test_data/load_url/foo.yaml @@ -18,5 +18,4 @@ spec: memory: 200Mi workingDir: /workspace/source serviceAccountName: tekton-bot - timeouts: - pipeline: 20m \ No newline at end of file + timeout: 0h20m0s \ No newline at end of file diff --git a/pkg/triggerconfig/inrepo/uses_resolver.go b/pkg/triggerconfig/inrepo/uses_resolver.go new file mode 100644 index 0000000..d19fc0e --- /dev/null +++ b/pkg/triggerconfig/inrepo/uses_resolver.go @@ -0,0 +1,249 @@ +package inrepo + +import ( + "context" + "fmt" + "os" + "strings" + + "github.com/jenkins-x/go-scm/scm" + + "github.com/sirupsen/logrus" + + "github.com/jenkins-x/lighthouse-client/pkg/filebrowser" + "github.com/jenkins-x/lighthouse-client/pkg/util" + "github.com/pkg/errors" + tektonv1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" +) + +// UsesResolver resolves the `uses:` URI syntax +type UsesResolver struct { + FileBrowsers *filebrowser.FileBrowsers + FetchCache filebrowser.FetchCache + Cache *ResolverCache + OwnerName string + RepoName string + SHA string + Dir string + Message string + DefaultValues *DefaultValues + LocalFileResolve bool +} + +var ( + // VersionStreamVersions allows you to register version stream values of ful repository names in the format + // `owner/name` mapping to the version SHA/branch/tag + VersionStreamVersions = map[string]string{} + + ignoreUsesCache = os.Getenv("NO_USES_CACHE") == "true" +) + +// UsesSteps lets resolve the sourceURI to a PipelineRun and find the step or steps +// for the given task name and/or step name then lets apply any overrides from the step +func (r *UsesResolver) UsesSteps(sourceURI string, taskName string, step tektonv1beta1.Step, ts *tektonv1beta1.TaskSpec, loc *UseLocation) ([]tektonv1beta1.Step, error) { + pr := r.Cache.GetPipelineRun(sourceURI, r.SHA) + if pr == nil || ignoreUsesCache { + data, err := r.GetData(sourceURI, false) + if err != nil { + return nil, errors.Wrapf(err, "failed to load URI %s", sourceURI) + } + if len(data) == 0 { + return nil, errors.Errorf("source URI not found: %s", sourceURI) + } + + pr, err = LoadTektonResourceAsPipelineRun(r, data) + if err != nil { + return nil, errors.Wrapf(err, "failed to resolve %s", sourceURI) + } + if pr == nil { + return nil, errors.Errorf("no PipelineRun for URI %s", sourceURI) + } + r.Cache.SetPipelineRun(sourceURI, r.SHA, pr) + } + + useTS, err := r.findSteps(sourceURI, pr.DeepCopy(), taskName, step) + if err != nil { + return nil, errors.Wrapf(err, "failed to ") + } + + originalSteps := ts.Steps + steps := useTS.Steps + OverrideTaskSpec(useTS, ts) + + // lets preserve any parameters, results, workspaces on the ts before overriding... + ctx := context.TODO() + useTS.Params = useParameterSpecs(ctx, useTS.Params, ts.Params) + useTS.Results = useResults(useTS.Results, ts.Results) + useTS.Workspaces = useWorkspaces(useTS.Workspaces, ts.Workspaces) + useTS.Sidecars = useSidecars(useTS.Sidecars, ts.Sidecars) + *ts = *useTS + ts.Steps = originalSteps + + err = UseParametersAndResults(ctx, loc, useTS) + if err != nil { + return steps, errors.Wrapf(err, "failed to resolve parameters and results") + } + return steps, nil +} + +// GetData gets the data from the given source URI +func (r *UsesResolver) GetData(path string, ignoreNotExist bool) ([]byte, error) { + data := r.Cache.GetData(path, r.SHA) + if len(data) > 0 { + return data, nil + } + + if strings.Contains(path, "://") { + data, err := getPipelineFromURL(path) + if err != nil { + return nil, errors.Wrapf(err, "failed to get pipeline from URL %s ", path) + } + return data, nil + } + + owner := r.OwnerName + repo := r.RepoName + sha := r.SHA + + gitURI, err := ParseGitURI(path) + if err != nil { + return nil, errors.Wrapf(err, "failed to parse git URI %s", path) + } + if gitURI == nil && r.LocalFileResolve { + if ignoreNotExist { + exists, err := util.FileExists(path) + if err != nil { + return nil, errors.Wrapf(err, "failed to check file exists %s", path) + } + if !exists { + return nil, nil + } + } + /* #nosec */ + data, err := os.ReadFile(path) + if err != nil { + return nil, errors.Wrapf(err, "failed to read file %s", path) + } + return data, nil + } + fb := r.FileBrowsers.LighthouseGitFileBrowser() + if gitURI != nil { + data := r.lookupDataCache(path) + if len(data) > 0 { + return data, nil + } + + owner = gitURI.Owner + repo = gitURI.Repository + path = gitURI.Path + sha = resolveCustomSha(owner, repo, gitURI.SHA) + + fb = r.FileBrowsers.GetFileBrowser(gitURI.Server) + if fb == nil { + return nil, errors.Errorf("could not find git file browser for server %s in uses: git URI %s", gitURI.Server, gitURI.String()) + } + } + data, err = fb.GetFile(owner, repo, path, sha, r.FetchCache) + if err != nil && IsScmNotFound(err) { + err = nil + } + if err != nil { + return nil, errors.Wrapf(err, "failed to find file %s in repo %s/%s with sha %s", path, owner, repo, sha) + } + if gitURI != nil { + r.Cache.SetData(path, r.SHA, data) + } + return data, nil +} + +// lets allow version stream versions to be exposed by environment variables +func resolveCustomSha(owner string, repo string, sha string) string { + if sha != "versionStream" { + return sha + } + fullName := scm.Join(owner, repo) + value := VersionStreamVersions[fullName] + envVar := VersionStreamEnvVar(owner, repo) + if value == "" { + value = os.Getenv(envVar) + } + if value != "" { + return value + } + logrus.WithFields(map[string]interface{}{ + "Owner": owner, + "Repo": repo, + }).Warnf("no version stream version environment variable: %s", envVar) + return "HEAD" +} + +// VersionStreamEnvVar creates an environment variable name +func VersionStreamEnvVar(owner string, repo string) string { + envVar := strings.ToUpper(fmt.Sprintf("LIGHTHOUSE_VERSIONSTREAM_%s_%s", owner, repo)) + envVar = strings.ReplaceAll(envVar, "-", "_") + envVar = strings.ReplaceAll(envVar, " ", "_") + envVar = strings.ReplaceAll(envVar, ".", "_") + return envVar +} + +func (r *UsesResolver) findSteps(sourceURI string, pr *tektonv1beta1.PipelineRun, taskName string, step tektonv1beta1.Step) (*tektonv1beta1.TaskSpec, error) { + if pr.Spec.PipelineSpec == nil { + return nil, errors.Errorf("source URI %s has no spec.pipelineSpec", sourceURI) + } + pipelineTasks := pr.Spec.PipelineSpec.Tasks + switch len(pipelineTasks) { + case 0: + return nil, errors.Errorf("source URI %s has no spec.pipelineSpec.tasks", sourceURI) + case 1: + return r.findTaskStep(sourceURI, pipelineTasks[0], step) + + default: + for _, task := range pipelineTasks { + if task.Name == taskName { + return r.findTaskStep(sourceURI, task, step) + } + } + return nil, errors.Errorf("source URI %s has multiple spec.pipelineSpec.tasks but none match task name %s", sourceURI, taskName) + } +} + +func (r *UsesResolver) findTaskStep(sourceURI string, task tektonv1beta1.PipelineTask, step tektonv1beta1.Step) (*tektonv1beta1.TaskSpec, error) { + ts := task.TaskSpec + if ts == nil { + return nil, errors.Errorf("source URI %s has no task spec for task %s", sourceURI, task.Name) + } + name := step.Name + if name == "" { + return &ts.TaskSpec, nil + } + + idx := strings.Index(name, ":") + suffix := "" + if idx > 0 { + suffix = name[idx+1:] + name = name[0:idx] + } + + taskSpec := task.TaskSpec.TaskSpec + for i := range ts.Steps { + s := &ts.Steps[i] + if s.Name == name { + replaceStep := *s + OverrideStep(&replaceStep, &step) + if suffix != "" { + replaceStep.Name = name + "-" + suffix + } + taskSpec.Steps = []tektonv1beta1.Step{replaceStep} + return &taskSpec, nil + } + } + return nil, errors.Errorf("source URI %s task %s has no step named %s", sourceURI, task.Name, name) +} + +func (r *UsesResolver) lookupDataCache(path string) []byte { + return nil +} + +func (r *UsesResolver) updateDataCache(path string, data []byte) { + +}