github.com/olli-ai/jx/v2@v2.0.400-0.20210921045218-14731b4dd448/pkg/cmd/step/syntax/step_syntax_effective_test.go (about)

     1  // +build unit
     2  
     3  package syntax_test
     4  
     5  import (
     6  	"io/ioutil"
     7  	"os"
     8  	"path"
     9  	"path/filepath"
    10  	"strings"
    11  	"testing"
    12  
    13  	"github.com/olli-ai/jx/v2/pkg/cmd/opts/step"
    14  	"github.com/olli-ai/jx/v2/pkg/tekton"
    15  
    16  	"github.com/olli-ai/jx/v2/pkg/versionstream"
    17  
    18  	"github.com/google/go-cmp/cmp/cmpopts"
    19  	"github.com/google/uuid"
    20  	"github.com/jenkins-x/jx-logging/pkg/log"
    21  	"github.com/olli-ai/jx/v2/pkg/cmd/opts"
    22  	"github.com/olli-ai/jx/v2/pkg/cmd/step/syntax"
    23  	"github.com/olli-ai/jx/v2/pkg/cmd/testhelpers"
    24  	"github.com/olli-ai/jx/v2/pkg/config"
    25  	"github.com/olli-ai/jx/v2/pkg/gits"
    26  	gits_test "github.com/olli-ai/jx/v2/pkg/gits/mocks"
    27  	helm_test "github.com/olli-ai/jx/v2/pkg/helm/mocks"
    28  	"github.com/olli-ai/jx/v2/pkg/jenkinsfile"
    29  	"github.com/olli-ai/jx/v2/pkg/kube"
    30  	jxsyntax "github.com/olli-ai/jx/v2/pkg/tekton/syntax"
    31  	sht "github.com/olli-ai/jx/v2/pkg/tekton/syntax/syntax_helpers_test"
    32  	"github.com/olli-ai/jx/v2/pkg/tests"
    33  	"github.com/stretchr/testify/assert"
    34  	tb "github.com/tektoncd/pipeline/test/builder"
    35  	corev1 "k8s.io/api/core/v1"
    36  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    37  	"k8s.io/apimachinery/pkg/runtime"
    38  	"knative.dev/pkg/kmp"
    39  	"sigs.k8s.io/yaml"
    40  )
    41  
    42  var (
    43  	overrideAfter  = jxsyntax.StepOverrideAfter
    44  	overrideBefore = jxsyntax.StepOverrideBefore
    45  )
    46  
    47  func TestCreateCanonicalPipeline(t *testing.T) {
    48  	t.Parallel()
    49  
    50  	log.SetOutput(ioutil.Discard)
    51  	defer log.SetOutput(os.Stderr)
    52  
    53  	testData := path.Join("..", "create", "test_data", "step_create_task")
    54  	_, err := os.Stat(testData)
    55  	assert.NoError(t, err)
    56  
    57  	testVersionsDir := path.Join(testData, "stable_versions")
    58  	packsDir := path.Join(testData, "packs")
    59  	_, err = os.Stat(packsDir)
    60  	assert.NoError(t, err)
    61  
    62  	// Override the DOCKER_REGISTRY_ORG env var for CI consistency
    63  	origDRO := os.Getenv("DOCKER_REGISTRY_ORG")
    64  	os.Setenv("DOCKER_REGISTRY_ORG", "abayer")
    65  	defer func() {
    66  		if origDRO != "" {
    67  			os.Setenv("DOCKER_REGISTRY_ORG", origDRO)
    68  		} else {
    69  			os.Unsetenv("DOCKER_REGISTRY_ORG")
    70  		}
    71  	}()
    72  
    73  	resolver := func(importFile *jenkinsfile.ImportFile) (string, error) {
    74  		dirPath := []string{packsDir, "import_dir", importFile.Import}
    75  		// lets handle cross platform paths in `importFile.File`
    76  		path := append(dirPath, strings.Split(importFile.File, "/")...)
    77  		return filepath.Join(path...), nil
    78  	}
    79  
    80  	cases := []struct {
    81  		name         string
    82  		pack         string
    83  		repoName     string
    84  		organization string
    85  		branch       string
    86  		customEnvs   []string
    87  		expected     *config.ProjectConfig
    88  	}{{
    89  		name:         "js_build_pack_with_yaml",
    90  		pack:         "javascript",
    91  		repoName:     "js-test-repo",
    92  		organization: "abayer",
    93  		branch:       "build-pack",
    94  		customEnvs:   []string{"DOCKER_REGISTRY=gcr.io"},
    95  		expected: &config.ProjectConfig{
    96  			BuildPack: "javascript",
    97  			PipelineConfig: &jenkinsfile.PipelineConfig{
    98  				Agent: &jxsyntax.Agent{
    99  					Container: "nodejs",
   100  					Label:     "jenkins-nodejs",
   101  				},
   102  				Env: []corev1.EnvVar{
   103  					{
   104  						Name:  "DOCKER_REGISTRY",
   105  						Value: "gcr.io",
   106  					},
   107  				},
   108  				Extends: &jenkinsfile.PipelineExtends{
   109  					File:   "javascript/pipeline.yaml",
   110  					Import: "classic",
   111  				},
   112  				Pipelines: jenkinsfile.Pipelines{
   113  					Post: &jenkinsfile.PipelineLifecycle{
   114  						Steps:    []*jxsyntax.Step{},
   115  						PreSteps: []*jxsyntax.Step{},
   116  					},
   117  					PullRequest: &jenkinsfile.PipelineLifecycles{
   118  						Pipeline: sht.ParsedPipeline(
   119  							sht.PipelineEnvVar("DOCKER_REGISTRY", "gcr.io"),
   120  							sht.PipelineOptions(
   121  								sht.PipelineContainerOptions(
   122  									sht.ContainerResourceRequests("400m", "512Mi"),
   123  									tb.EnvVar("DOCKER_CONFIG", "/home/jenkins/.docker/"),
   124  									sht.EnvVar("DOCKER_REGISTRY", "gcr.io"),
   125  									tb.EnvVar("GIT_AUTHOR_EMAIL", "jenkins-x@googlegroups.com"),
   126  									tb.EnvVar("GIT_AUTHOR_NAME", "jenkins-x-bot"),
   127  									tb.EnvVar("GIT_COMMITTER_EMAIL", "jenkins-x@googlegroups.com"),
   128  									tb.EnvVar("GIT_COMMITTER_NAME", "jenkins-x-bot"),
   129  									tb.EnvVar("JENKINS_URL", "http://jenkins:8080"),
   130  									tb.EnvVar("TILLER_NAMESPACE", "kube-system"),
   131  									tb.EnvVar("XDG_CONFIG_HOME", "/home/jenkins"),
   132  									sht.ContainerSecurityContext(true),
   133  									tb.VolumeMount("workspace-volume", "/home/jenkins"),
   134  									tb.VolumeMount("docker-daemon", "/var/run/docker.sock"),
   135  									tb.VolumeMount("volume-0", "/home/jenkins/.docker"),
   136  								),
   137  								sht.PipelineVolume(&corev1.Volume{
   138  									Name: "workspace-volume",
   139  									VolumeSource: corev1.VolumeSource{
   140  										EmptyDir: &corev1.EmptyDirVolumeSource{},
   141  									},
   142  								}),
   143  								sht.PipelineVolume(&corev1.Volume{
   144  									Name: "docker-daemon",
   145  									VolumeSource: corev1.VolumeSource{
   146  										HostPath: &corev1.HostPathVolumeSource{
   147  											Path: "/var/run/docker.sock",
   148  										},
   149  									},
   150  								}),
   151  								sht.PipelineVolume(&corev1.Volume{
   152  									Name: "volume-0",
   153  									VolumeSource: corev1.VolumeSource{
   154  										Secret: &corev1.SecretVolumeSource{
   155  											SecretName: "jenkins-docker-cfg",
   156  										},
   157  									},
   158  								}),
   159  							),
   160  							sht.PipelineStage("from-build-pack",
   161  								sht.StageAgent("nodejs"),
   162  								sht.StageDir("/workspace/source"),
   163  								sht.StageStep(sht.StepCmd("npm install"), sht.StepDir("/workspace/source"),
   164  									sht.StepImage("nodejs"), sht.StepName("build-npm-install")),
   165  								sht.StageStep(sht.StepCmd("CI=true DISPLAY=:99 npm test"), sht.StepDir("/workspace/source"),
   166  									sht.StepImage("nodejs"), sht.StepName("build-step3")),
   167  								sht.StageStep(sht.StepCmd("/kaniko/executor"), sht.StepDir("/workspace/source"),
   168  									sht.StepImage(jxsyntax.KanikoDockerImage), sht.StepName("build-container-build"),
   169  									sht.StepArg("--cache=true"), sht.StepArg("--cache-dir=/workspace"),
   170  									sht.StepArg("--context=/workspace/source"), sht.StepArg("--dockerfile=/workspace/source/Dockerfile"),
   171  									sht.StepArg("--destination=gcr.io/abayer/js-test-repo:${inputs.params.version}"),
   172  									sht.StepArg("--cache-repo=gcr.io//cache")),
   173  								sht.StageStep(sht.StepCmd("jx step post build --image $DOCKER_REGISTRY/$ORG/$APP_NAME:$PREVIEW_VERSION"),
   174  									sht.StepDir("/workspace/source"), sht.StepImage("nodejs"), sht.StepName("postbuild-post-build")),
   175  								sht.StageStep(sht.StepCmd("make preview"), sht.StepDir("/workspace/source/charts/preview"),
   176  									sht.StepImage("nodejs"), sht.StepName("promote-make-preview")),
   177  								sht.StageStep(sht.StepCmd("jx preview --app $APP_NAME --dir ../.."), sht.StepDir("/workspace/source/charts/preview"),
   178  									sht.StepImage("nodejs"), sht.StepName("promote-jx-preview")),
   179  							),
   180  						),
   181  					},
   182  					Release: &jenkinsfile.PipelineLifecycles{
   183  						Pipeline: sht.ParsedPipeline(
   184  							sht.PipelineEnvVar("DOCKER_REGISTRY", "gcr.io"),
   185  							sht.PipelineOptions(
   186  								sht.PipelineContainerOptions(
   187  									sht.ContainerResourceRequests("400m", "512Mi"),
   188  									tb.EnvVar("DOCKER_CONFIG", "/home/jenkins/.docker/"),
   189  									sht.EnvVar("DOCKER_REGISTRY", "gcr.io"),
   190  									tb.EnvVar("GIT_AUTHOR_EMAIL", "jenkins-x@googlegroups.com"),
   191  									tb.EnvVar("GIT_AUTHOR_NAME", "jenkins-x-bot"),
   192  									tb.EnvVar("GIT_COMMITTER_EMAIL", "jenkins-x@googlegroups.com"),
   193  									tb.EnvVar("GIT_COMMITTER_NAME", "jenkins-x-bot"),
   194  									tb.EnvVar("JENKINS_URL", "http://jenkins:8080"),
   195  									tb.EnvVar("TILLER_NAMESPACE", "kube-system"),
   196  									tb.EnvVar("XDG_CONFIG_HOME", "/home/jenkins"),
   197  									sht.ContainerSecurityContext(true),
   198  									tb.VolumeMount("workspace-volume", "/home/jenkins"),
   199  									tb.VolumeMount("docker-daemon", "/var/run/docker.sock"),
   200  									tb.VolumeMount("volume-0", "/home/jenkins/.docker"),
   201  								),
   202  								sht.PipelineVolume(&corev1.Volume{
   203  									Name: "workspace-volume",
   204  									VolumeSource: corev1.VolumeSource{
   205  										EmptyDir: &corev1.EmptyDirVolumeSource{},
   206  									},
   207  								}),
   208  								sht.PipelineVolume(&corev1.Volume{
   209  									Name: "docker-daemon",
   210  									VolumeSource: corev1.VolumeSource{
   211  										HostPath: &corev1.HostPathVolumeSource{
   212  											Path: "/var/run/docker.sock",
   213  										},
   214  									},
   215  								}),
   216  								sht.PipelineVolume(&corev1.Volume{
   217  									Name: "volume-0",
   218  									VolumeSource: corev1.VolumeSource{
   219  										Secret: &corev1.SecretVolumeSource{
   220  											SecretName: "jenkins-docker-cfg",
   221  										},
   222  									},
   223  								}),
   224  							),
   225  							sht.PipelineStage("from-build-pack",
   226  								sht.StageAgent("nodejs"),
   227  								sht.StageDir("/workspace/source"),
   228  								sht.StageStep(sht.StepCmd("jx step git credentials"), sht.StepDir("/workspace/source"),
   229  									sht.StepImage("nodejs"), sht.StepName("setup-jx-git-credentials")),
   230  								sht.StageStep(sht.StepCmd("npm install"), sht.StepDir("/workspace/source"),
   231  									sht.StepImage("nodejs"), sht.StepName("build-npm-install")),
   232  								sht.StageStep(sht.StepCmd("CI=true DISPLAY=:99 npm test"), sht.StepDir("/workspace/source"),
   233  									sht.StepImage("nodejs"), sht.StepName("build-npm-test")),
   234  								sht.StageStep(sht.StepCmd("/kaniko/executor"), sht.StepDir("/workspace/source"),
   235  									sht.StepImage(jxsyntax.KanikoDockerImage), sht.StepName("build-container-build"),
   236  									sht.StepArg("--cache=true"), sht.StepArg("--cache-dir=/workspace"),
   237  									sht.StepArg("--context=/workspace/source"), sht.StepArg("--dockerfile=/workspace/source/Dockerfile"),
   238  									sht.StepArg("--destination=gcr.io/abayer/js-test-repo:${inputs.params.version}"),
   239  									sht.StepArg("--cache-repo=gcr.io//cache")),
   240  								sht.StageStep(sht.StepCmd("jx step post build --image $DOCKER_REGISTRY/$ORG/$APP_NAME:${VERSION}"),
   241  									sht.StepDir("/workspace/source"), sht.StepImage("nodejs"), sht.StepName("build-post-build")),
   242  								sht.StageStep(sht.StepCmd("jx step changelog --batch-mode --version v${VERSION}"),
   243  									sht.StepDir("/workspace/source/charts/js-test-repo"), sht.StepImage("nodejs"),
   244  									sht.StepName("promote-changelog")),
   245  								sht.StageStep(sht.StepCmd("jx step helm release"), sht.StepDir("/workspace/source/charts/js-test-repo"),
   246  									sht.StepImage("nodejs"), sht.StepName("promote-helm-release")),
   247  								sht.StageStep(sht.StepCmd("jx promote -b --all-auto --timeout 1h --version ${VERSION}"),
   248  									sht.StepDir("/workspace/source/charts/js-test-repo"),
   249  									sht.StepImage("nodejs"), sht.StepName("promote-jx-promote")),
   250  							),
   251  						),
   252  						SetVersion: &jenkinsfile.PipelineLifecycle{
   253  							Steps: []*jxsyntax.Step{{
   254  								Image: "nodejs",
   255  								Steps: []*jxsyntax.Step{{
   256  									Comment: "so we can retrieve the version in later steps",
   257  									Name:    "next-version",
   258  									Sh:      "echo \\$(jx-release-version) > VERSION",
   259  									Steps:   []*jxsyntax.Step{},
   260  								}, {
   261  									Name:  "tag-version",
   262  									Sh:    "jx step tag --version \\$(cat VERSION)",
   263  									Steps: []*jxsyntax.Step{},
   264  								}},
   265  							}},
   266  							PreSteps: []*jxsyntax.Step{},
   267  						},
   268  					},
   269  				},
   270  			},
   271  		},
   272  	}, {
   273  		name:         "js_build_pack",
   274  		pack:         "javascript",
   275  		repoName:     "js-test-repo",
   276  		organization: "abayer",
   277  		branch:       "build-pack",
   278  		expected: &config.ProjectConfig{
   279  			PipelineConfig: &jenkinsfile.PipelineConfig{
   280  				Agent: &jxsyntax.Agent{
   281  					Container: "nodejs",
   282  					Label:     "jenkins-nodejs",
   283  				},
   284  				Env: []corev1.EnvVar{},
   285  				Extends: &jenkinsfile.PipelineExtends{
   286  					File:   "javascript/pipeline.yaml",
   287  					Import: "classic",
   288  				},
   289  				Pipelines: jenkinsfile.Pipelines{
   290  					Post: &jenkinsfile.PipelineLifecycle{
   291  						Steps:    []*jxsyntax.Step{},
   292  						PreSteps: []*jxsyntax.Step{},
   293  					},
   294  					PullRequest: &jenkinsfile.PipelineLifecycles{
   295  						Pipeline: sht.ParsedPipeline(
   296  							sht.PipelineOptions(
   297  								sht.PipelineContainerOptions(
   298  									sht.ContainerResourceRequests("400m", "512Mi"),
   299  									tb.EnvVar("DOCKER_CONFIG", "/home/jenkins/.docker/"),
   300  									sht.EnvVarFrom("DOCKER_REGISTRY", &corev1.EnvVarSource{
   301  										ConfigMapKeyRef: &corev1.ConfigMapKeySelector{
   302  											Key: "docker.registry",
   303  											LocalObjectReference: corev1.LocalObjectReference{
   304  												Name: "jenkins-x-docker-registry",
   305  											}}}),
   306  									tb.EnvVar("GIT_AUTHOR_EMAIL", "jenkins-x@googlegroups.com"),
   307  									tb.EnvVar("GIT_AUTHOR_NAME", "jenkins-x-bot"),
   308  									tb.EnvVar("GIT_COMMITTER_EMAIL", "jenkins-x@googlegroups.com"),
   309  									tb.EnvVar("GIT_COMMITTER_NAME", "jenkins-x-bot"),
   310  									tb.EnvVar("JENKINS_URL", "http://jenkins:8080"),
   311  									tb.EnvVar("TILLER_NAMESPACE", "kube-system"),
   312  									tb.EnvVar("XDG_CONFIG_HOME", "/home/jenkins"),
   313  									sht.ContainerSecurityContext(true),
   314  									tb.VolumeMount("workspace-volume", "/home/jenkins"),
   315  									tb.VolumeMount("docker-daemon", "/var/run/docker.sock"),
   316  									tb.VolumeMount("volume-0", "/home/jenkins/.docker"),
   317  								),
   318  								sht.PipelineVolume(&corev1.Volume{
   319  									Name: "workspace-volume",
   320  									VolumeSource: corev1.VolumeSource{
   321  										EmptyDir: &corev1.EmptyDirVolumeSource{},
   322  									},
   323  								}),
   324  								sht.PipelineVolume(&corev1.Volume{
   325  									Name: "docker-daemon",
   326  									VolumeSource: corev1.VolumeSource{
   327  										HostPath: &corev1.HostPathVolumeSource{
   328  											Path: "/var/run/docker.sock",
   329  										},
   330  									},
   331  								}),
   332  								sht.PipelineVolume(&corev1.Volume{
   333  									Name: "volume-0",
   334  									VolumeSource: corev1.VolumeSource{
   335  										Secret: &corev1.SecretVolumeSource{
   336  											SecretName: "jenkins-docker-cfg",
   337  										},
   338  									},
   339  								}),
   340  							),
   341  							sht.PipelineStage("from-build-pack",
   342  								sht.StageAgent("nodejs"),
   343  								sht.StageDir("/workspace/source"),
   344  								sht.StageStep(sht.StepCmd("npm install"), sht.StepDir("/workspace/source"),
   345  									sht.StepImage("nodejs"), sht.StepName("build-npm-install")),
   346  								sht.StageStep(sht.StepCmd("CI=true DISPLAY=:99 npm test"), sht.StepDir("/workspace/source"),
   347  									sht.StepImage("nodejs"), sht.StepName("build-step3")),
   348  								sht.StageStep(sht.StepCmd("/kaniko/executor"), sht.StepDir("/workspace/source"),
   349  									sht.StepImage(jxsyntax.KanikoDockerImage), sht.StepName("build-container-build"),
   350  									sht.StepArg("--cache=true"), sht.StepArg("--cache-dir=/workspace"),
   351  									sht.StepArg("--context=/workspace/source"), sht.StepArg("--dockerfile=/workspace/source/Dockerfile"),
   352  									sht.StepArg("--destination=gcr.io/abayer/js-test-repo:${inputs.params.version}"),
   353  									sht.StepArg("--cache-repo=gcr.io//cache")),
   354  								sht.StageStep(sht.StepCmd("jx step post build --image $DOCKER_REGISTRY/$ORG/$APP_NAME:$PREVIEW_VERSION"),
   355  									sht.StepDir("/workspace/source"), sht.StepImage("nodejs"), sht.StepName("postbuild-post-build")),
   356  								sht.StageStep(sht.StepCmd("make preview"), sht.StepDir("/workspace/source/charts/preview"),
   357  									sht.StepImage("nodejs"), sht.StepName("promote-make-preview")),
   358  								sht.StageStep(sht.StepCmd("jx preview --app $APP_NAME --dir ../.."), sht.StepDir("/workspace/source/charts/preview"),
   359  									sht.StepImage("nodejs"), sht.StepName("promote-jx-preview")),
   360  							),
   361  						),
   362  					},
   363  					Release: &jenkinsfile.PipelineLifecycles{
   364  						Pipeline: sht.ParsedPipeline(
   365  							sht.PipelineOptions(
   366  								sht.PipelineContainerOptions(
   367  									sht.ContainerResourceRequests("400m", "512Mi"),
   368  									tb.EnvVar("DOCKER_CONFIG", "/home/jenkins/.docker/"),
   369  									sht.EnvVarFrom("DOCKER_REGISTRY", &corev1.EnvVarSource{
   370  										ConfigMapKeyRef: &corev1.ConfigMapKeySelector{
   371  											Key: "docker.registry",
   372  											LocalObjectReference: corev1.LocalObjectReference{
   373  												Name: "jenkins-x-docker-registry",
   374  											}}}),
   375  									tb.EnvVar("GIT_AUTHOR_EMAIL", "jenkins-x@googlegroups.com"),
   376  									tb.EnvVar("GIT_AUTHOR_NAME", "jenkins-x-bot"),
   377  									tb.EnvVar("GIT_COMMITTER_EMAIL", "jenkins-x@googlegroups.com"),
   378  									tb.EnvVar("GIT_COMMITTER_NAME", "jenkins-x-bot"),
   379  									tb.EnvVar("JENKINS_URL", "http://jenkins:8080"),
   380  									tb.EnvVar("TILLER_NAMESPACE", "kube-system"),
   381  									tb.EnvVar("XDG_CONFIG_HOME", "/home/jenkins"),
   382  									sht.ContainerSecurityContext(true),
   383  									tb.VolumeMount("workspace-volume", "/home/jenkins"),
   384  									tb.VolumeMount("docker-daemon", "/var/run/docker.sock"),
   385  									tb.VolumeMount("volume-0", "/home/jenkins/.docker"),
   386  								),
   387  								sht.PipelineVolume(&corev1.Volume{
   388  									Name: "workspace-volume",
   389  									VolumeSource: corev1.VolumeSource{
   390  										EmptyDir: &corev1.EmptyDirVolumeSource{},
   391  									},
   392  								}),
   393  								sht.PipelineVolume(&corev1.Volume{
   394  									Name: "docker-daemon",
   395  									VolumeSource: corev1.VolumeSource{
   396  										HostPath: &corev1.HostPathVolumeSource{
   397  											Path: "/var/run/docker.sock",
   398  										},
   399  									},
   400  								}),
   401  								sht.PipelineVolume(&corev1.Volume{
   402  									Name: "volume-0",
   403  									VolumeSource: corev1.VolumeSource{
   404  										Secret: &corev1.SecretVolumeSource{
   405  											SecretName: "jenkins-docker-cfg",
   406  										},
   407  									},
   408  								}),
   409  							),
   410  							sht.PipelineStage("from-build-pack",
   411  								sht.StageAgent("nodejs"),
   412  								sht.StageDir("/workspace/source"),
   413  								sht.StageStep(sht.StepCmd("jx step git credentials"), sht.StepDir("/workspace/source"),
   414  									sht.StepImage("nodejs"), sht.StepName("setup-jx-git-credentials")),
   415  								sht.StageStep(sht.StepCmd("npm install"), sht.StepDir("/workspace/source"),
   416  									sht.StepImage("nodejs"), sht.StepName("build-npm-install")),
   417  								sht.StageStep(sht.StepCmd("CI=true DISPLAY=:99 npm test"), sht.StepDir("/workspace/source"),
   418  									sht.StepImage("nodejs"), sht.StepName("build-npm-test")),
   419  								sht.StageStep(sht.StepCmd("/kaniko/executor"), sht.StepDir("/workspace/source"),
   420  									sht.StepImage(jxsyntax.KanikoDockerImage), sht.StepName("build-container-build"),
   421  									sht.StepArg("--cache=true"), sht.StepArg("--cache-dir=/workspace"),
   422  									sht.StepArg("--context=/workspace/source"), sht.StepArg("--dockerfile=/workspace/source/Dockerfile"),
   423  									sht.StepArg("--destination=gcr.io/abayer/js-test-repo:${inputs.params.version}"),
   424  									sht.StepArg("--cache-repo=gcr.io//cache")),
   425  								sht.StageStep(sht.StepCmd("jx step post build --image $DOCKER_REGISTRY/$ORG/$APP_NAME:${VERSION}"),
   426  									sht.StepDir("/workspace/source"), sht.StepImage("nodejs"), sht.StepName("build-post-build")),
   427  								sht.StageStep(sht.StepCmd("jx step changelog --batch-mode --version v${VERSION}"),
   428  									sht.StepDir("/workspace/source/charts/js-test-repo"), sht.StepImage("nodejs"),
   429  									sht.StepName("promote-changelog")),
   430  								sht.StageStep(sht.StepCmd("jx step helm release"), sht.StepDir("/workspace/source/charts/js-test-repo"),
   431  									sht.StepImage("nodejs"), sht.StepName("promote-helm-release")),
   432  								sht.StageStep(sht.StepCmd("jx promote -b --all-auto --timeout 1h --version ${VERSION}"),
   433  									sht.StepDir("/workspace/source/charts/js-test-repo"),
   434  									sht.StepImage("nodejs"), sht.StepName("promote-jx-promote")),
   435  							),
   436  						),
   437  						SetVersion: &jenkinsfile.PipelineLifecycle{
   438  							Steps: []*jxsyntax.Step{{
   439  								Image: "nodejs",
   440  								Steps: []*jxsyntax.Step{{
   441  									Comment: "so we can retrieve the version in later steps",
   442  									Name:    "next-version",
   443  									Sh:      "echo \\$(jx-release-version) > VERSION",
   444  									Steps:   []*jxsyntax.Step{},
   445  								}, {
   446  									Name:  "tag-version",
   447  									Sh:    "jx step tag --version \\$(cat VERSION)",
   448  									Steps: []*jxsyntax.Step{},
   449  								}},
   450  							}},
   451  							PreSteps: []*jxsyntax.Step{},
   452  						},
   453  					},
   454  				},
   455  			},
   456  		},
   457  	}, {
   458  		name:         "default-in-buildpack",
   459  		pack:         "default-pipeline",
   460  		repoName:     "golang-qs-test",
   461  		organization: "abayer",
   462  		branch:       "master",
   463  		expected: &config.ProjectConfig{
   464  			PipelineConfig: &jenkinsfile.PipelineConfig{
   465  				Agent: &jxsyntax.Agent{
   466  					Container: "go",
   467  					Label:     "builder-go",
   468  				},
   469  				Env: []corev1.EnvVar{},
   470  				Pipelines: jenkinsfile.Pipelines{
   471  					Default: sht.ParsedPipeline(
   472  						sht.PipelineAgent("go"),
   473  						sht.PipelineStage("from-build-pack",
   474  							sht.StageStep(sht.StepCmd("make build"), sht.StepName("build")),
   475  							sht.StageStep(sht.StepCmd("jx step helm build"), sht.StepName("helm-build")),
   476  						),
   477  					),
   478  					Feature: &jenkinsfile.PipelineLifecycles{
   479  						Pipeline: sht.ParsedPipeline(
   480  							sht.PipelineAgent("go"),
   481  							sht.PipelineStage("from-build-pack",
   482  								sht.StageDir("/workspace/source"),
   483  								sht.StageStep(sht.StepCmd("make build"), sht.StepName("build")),
   484  								sht.StageStep(sht.StepCmd("jx step helm build"), sht.StepName("helm-build")),
   485  							),
   486  						),
   487  					},
   488  					PullRequest: &jenkinsfile.PipelineLifecycles{
   489  						Pipeline: sht.ParsedPipeline(
   490  							sht.PipelineAgent("go"),
   491  							sht.PipelineStage("from-build-pack",
   492  								sht.StageDir("/workspace/source"),
   493  								sht.StageStep(sht.StepCmd("make build"), sht.StepName("build")),
   494  								sht.StageStep(sht.StepCmd("jx step helm build"), sht.StepName("helm-build")),
   495  							),
   496  						),
   497  					},
   498  					Release: &jenkinsfile.PipelineLifecycles{
   499  						Pipeline: sht.ParsedPipeline(
   500  							sht.PipelineAgent("go"),
   501  							sht.PipelineStage("from-build-pack",
   502  								sht.StageDir("/workspace/source"),
   503  								sht.StageStep(sht.StepCmd("make build"), sht.StepName("build")),
   504  								sht.StageStep(sht.StepCmd("jx step helm build"), sht.StepName("helm-build")),
   505  							),
   506  						),
   507  					},
   508  				},
   509  			},
   510  		},
   511  	}, {
   512  		name:         "add-env-to-default-in-buildpack",
   513  		pack:         "default-pipeline",
   514  		repoName:     "golang-qs-test",
   515  		organization: "abayer",
   516  		branch:       "master",
   517  		expected: &config.ProjectConfig{
   518  			PipelineConfig: &jenkinsfile.PipelineConfig{
   519  				Agent: &jxsyntax.Agent{
   520  					Image: "go",
   521  					Label: "builder-go",
   522  				},
   523  				Env: []corev1.EnvVar{{
   524  					Name:  "FRUIT",
   525  					Value: "BANANA",
   526  				}, {
   527  					Name:  "GIT_AUTHOR_NAME",
   528  					Value: "somebodyelse",
   529  				}},
   530  				Pipelines: jenkinsfile.Pipelines{
   531  					Feature: &jenkinsfile.PipelineLifecycles{
   532  						Pipeline: sht.ParsedPipeline(
   533  							sht.PipelineAgent("go"),
   534  							sht.PipelineEnvVar("FRUIT", "BANANA"),
   535  							sht.PipelineEnvVar("GIT_AUTHOR_NAME", "somebodyelse"),
   536  							sht.PipelineStage("from-build-pack",
   537  								sht.StageDir("/workspace/source"),
   538  								sht.StageStep(sht.StepCmd("make build"), sht.StepName("build")),
   539  								sht.StageStep(sht.StepCmd("jx step helm build"), sht.StepName("helm-build")),
   540  							),
   541  						),
   542  					},
   543  					PullRequest: &jenkinsfile.PipelineLifecycles{
   544  						Pipeline: sht.ParsedPipeline(
   545  							sht.PipelineAgent("go"),
   546  							sht.PipelineEnvVar("FRUIT", "BANANA"),
   547  							sht.PipelineEnvVar("GIT_AUTHOR_NAME", "somebodyelse"),
   548  							sht.PipelineStage("from-build-pack",
   549  								sht.StageDir("/workspace/source"),
   550  								sht.StageStep(sht.StepCmd("make build"), sht.StepName("build")),
   551  								sht.StageStep(sht.StepCmd("jx step helm build"), sht.StepName("helm-build")),
   552  							),
   553  						),
   554  					},
   555  					Release: &jenkinsfile.PipelineLifecycles{
   556  						Pipeline: sht.ParsedPipeline(
   557  							sht.PipelineAgent("go"),
   558  							sht.PipelineEnvVar("FRUIT", "BANANA"),
   559  							sht.PipelineEnvVar("GIT_AUTHOR_NAME", "somebodyelse"),
   560  							sht.PipelineStage("from-build-pack",
   561  								sht.StageDir("/workspace/source"),
   562  								sht.StageStep(sht.StepCmd("make build"), sht.StepName("build")),
   563  								sht.StageStep(sht.StepCmd("jx step helm build"), sht.StepName("helm-build")),
   564  							),
   565  						),
   566  					},
   567  				},
   568  			},
   569  		},
   570  	}, {
   571  		name:         "append-and-prepend-stage-steps",
   572  		pack:         "maven",
   573  		repoName:     "jx-demo-qs",
   574  		organization: "abayer",
   575  		branch:       "master",
   576  		expected: &config.ProjectConfig{
   577  			PipelineConfig: &jenkinsfile.PipelineConfig{
   578  				Agent: &jxsyntax.Agent{
   579  					Image: "maven",
   580  					Label: "jenkins-maven",
   581  				},
   582  				Env: []corev1.EnvVar{{
   583  					Name:  "FRUIT",
   584  					Value: "BANANA",
   585  				}, {
   586  					Name:  "GIT_AUTHOR_NAME",
   587  					Value: "somebodyelse",
   588  				}},
   589  				Pipelines: jenkinsfile.Pipelines{
   590  					Overrides: []*jxsyntax.PipelineOverride{{
   591  						Pipeline: "release",
   592  						Stage:    "build",
   593  						Steps: []*jxsyntax.Step{{
   594  							Sh: "echo hi there",
   595  						}},
   596  						Type: &overrideBefore,
   597  					}, {
   598  						Pipeline: "release",
   599  						Stage:    "build",
   600  						Steps: []*jxsyntax.Step{{
   601  							Sh: "echo goodbye",
   602  						}, {
   603  							Sh: "echo wait why am i here",
   604  						}},
   605  						Type: &overrideAfter,
   606  					}},
   607  					Post: &jenkinsfile.PipelineLifecycle{
   608  						Steps:    []*jxsyntax.Step{},
   609  						PreSteps: []*jxsyntax.Step{},
   610  					},
   611  					PullRequest: &jenkinsfile.PipelineLifecycles{
   612  						Pipeline: sht.ParsedPipeline(
   613  							sht.PipelineEnvVar("FRUIT", "BANANA"),
   614  							sht.PipelineEnvVar("GIT_AUTHOR_NAME", "somebodyelse"),
   615  							sht.PipelineOptions(
   616  								sht.PipelineContainerOptions(
   617  									tb.EnvVar("DOCKER_CONFIG", "/home/jenkins/.docker/"),
   618  									sht.EnvVarFrom("DOCKER_REGISTRY", &corev1.EnvVarSource{
   619  										ConfigMapKeyRef: &corev1.ConfigMapKeySelector{
   620  											Key: "docker.registry",
   621  											LocalObjectReference: corev1.LocalObjectReference{
   622  												Name: "jenkins-x-docker-registry",
   623  											}}}),
   624  									tb.EnvVar("FRUIT", "BANANA"),
   625  									tb.EnvVar("GIT_AUTHOR_EMAIL", "jenkins-x@googlegroups.com"),
   626  									tb.EnvVar("GIT_AUTHOR_NAME", "somebodyelse"),
   627  									tb.EnvVar("GIT_COMMITTER_EMAIL", "jenkins-x@googlegroups.com"),
   628  									tb.EnvVar("GIT_COMMITTER_NAME", "jenkins-x-bot"),
   629  									tb.EnvVar("JENKINS_URL", "http://jenkins:8080"),
   630  									tb.EnvVar("TILLER_NAMESPACE", "kube-system"),
   631  									tb.EnvVar("XDG_CONFIG_HOME", "/home/jenkins"),
   632  									tb.EnvVar("_JAVA_OPTIONS", "-XX:+UnlockExperimentalVMOptions -Dsun.zip.disableMemoryMapping=true -XX:+UseParallelGC -XX:MinHeapFreeRatio=5 -XX:MaxHeapFreeRatio=10 -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -Xms10m -Xmx192m"),
   633  									sht.ContainerSecurityContext(true),
   634  									tb.VolumeMount("workspace-volume", "/home/jenkins"),
   635  									tb.VolumeMount("docker-daemon", "/var/run/docker.sock"),
   636  									tb.VolumeMount("volume-0", "/root/.m2/"),
   637  									tb.VolumeMount("volume-1", "/home/jenkins/.docker"),
   638  									tb.VolumeMount("volume-2", "/home/jenkins/.gnupg"),
   639  								),
   640  								sht.PipelineVolume(&corev1.Volume{
   641  									Name: "workspace-volume",
   642  									VolumeSource: corev1.VolumeSource{
   643  										EmptyDir: &corev1.EmptyDirVolumeSource{},
   644  									},
   645  								}),
   646  								sht.PipelineVolume(&corev1.Volume{
   647  									Name: "docker-daemon",
   648  									VolumeSource: corev1.VolumeSource{
   649  										HostPath: &corev1.HostPathVolumeSource{
   650  											Path: "/var/run/docker.sock",
   651  										},
   652  									},
   653  								}),
   654  								sht.PipelineVolume(&corev1.Volume{
   655  									Name: "volume-0",
   656  									VolumeSource: corev1.VolumeSource{
   657  										Secret: &corev1.SecretVolumeSource{
   658  											SecretName: "jenkins-maven-settings",
   659  										},
   660  									},
   661  								}),
   662  								sht.PipelineVolume(&corev1.Volume{
   663  									Name: "volume-1",
   664  									VolumeSource: corev1.VolumeSource{
   665  										Secret: &corev1.SecretVolumeSource{
   666  											SecretName: "jenkins-docker-cfg",
   667  										},
   668  									},
   669  								}),
   670  								sht.PipelineVolume(&corev1.Volume{
   671  									Name: "volume-2",
   672  									VolumeSource: corev1.VolumeSource{
   673  										Secret: &corev1.SecretVolumeSource{
   674  											SecretName: "jenkins-release-gpg",
   675  										},
   676  									},
   677  								}),
   678  							),
   679  							sht.PipelineStage("from-build-pack",
   680  								sht.StageAgent("maven"),
   681  								sht.StageDir("/workspace/source"),
   682  								sht.StageStep(sht.StepCmd("mvn versions:set -DnewVersion=$PREVIEW_VERSION"), sht.StepImage("maven"),
   683  									sht.StepDir("/workspace/source"), sht.StepName("build-set-version")),
   684  								sht.StageStep(sht.StepCmd("mvn install"), sht.StepImage("maven"), sht.StepDir("/workspace/source"),
   685  									sht.StepName("build-mvn-install")),
   686  								sht.StageStep(sht.StepCmd("skaffold version"), sht.StepImage("maven"), sht.StepDir("/workspace/source"),
   687  									sht.StepName("build-skaffold-version")),
   688  								sht.StageStep(sht.StepCmd("/kaniko/executor"), sht.StepDir("/workspace/source"),
   689  									sht.StepImage(jxsyntax.KanikoDockerImage), sht.StepName("build-container-build"),
   690  									sht.StepArg("--cache=true"), sht.StepArg("--cache-dir=/workspace"),
   691  									sht.StepArg("--context=/workspace/source"), sht.StepArg("--dockerfile=/workspace/source/Dockerfile"),
   692  									sht.StepArg("--destination=gcr.io/abayer/jx-demo-qs:${inputs.params.version}"),
   693  									sht.StepArg("--cache-repo=gcr.io//cache")),
   694  								sht.StageStep(sht.StepCmd("jx step post build --image $DOCKER_REGISTRY/$ORG/$APP_NAME:$PREVIEW_VERSION"),
   695  									sht.StepDir("/workspace/source"), sht.StepImage("maven"), sht.StepName("postbuild-post-build")),
   696  								sht.StageStep(sht.StepCmd("make preview"), sht.StepDir("/workspace/source/charts/preview"),
   697  									sht.StepImage("maven"), sht.StepName("promote-make-preview")),
   698  								sht.StageStep(sht.StepCmd("jx preview --app $APP_NAME --dir ../.."), sht.StepDir("/workspace/source/charts/preview"),
   699  									sht.StepImage("maven"), sht.StepName("promote-jx-preview")),
   700  							),
   701  						),
   702  					},
   703  					Release: &jenkinsfile.PipelineLifecycles{
   704  						Pipeline: sht.ParsedPipeline(
   705  							sht.PipelineEnvVar("FRUIT", "BANANA"),
   706  							sht.PipelineEnvVar("GIT_AUTHOR_NAME", "somebodyelse"),
   707  							sht.PipelineOptions(
   708  								sht.PipelineContainerOptions(
   709  									tb.EnvVar("DOCKER_CONFIG", "/home/jenkins/.docker/"),
   710  									sht.EnvVarFrom("DOCKER_REGISTRY", &corev1.EnvVarSource{
   711  										ConfigMapKeyRef: &corev1.ConfigMapKeySelector{
   712  											Key: "docker.registry",
   713  											LocalObjectReference: corev1.LocalObjectReference{
   714  												Name: "jenkins-x-docker-registry",
   715  											}}}),
   716  									tb.EnvVar("FRUIT", "BANANA"),
   717  									tb.EnvVar("GIT_AUTHOR_EMAIL", "jenkins-x@googlegroups.com"),
   718  									tb.EnvVar("GIT_AUTHOR_NAME", "somebodyelse"),
   719  									tb.EnvVar("GIT_COMMITTER_EMAIL", "jenkins-x@googlegroups.com"),
   720  									tb.EnvVar("GIT_COMMITTER_NAME", "jenkins-x-bot"),
   721  									tb.EnvVar("JENKINS_URL", "http://jenkins:8080"),
   722  									tb.EnvVar("TILLER_NAMESPACE", "kube-system"),
   723  									tb.EnvVar("XDG_CONFIG_HOME", "/home/jenkins"),
   724  									tb.EnvVar("_JAVA_OPTIONS", "-XX:+UnlockExperimentalVMOptions -Dsun.zip.disableMemoryMapping=true -XX:+UseParallelGC -XX:MinHeapFreeRatio=5 -XX:MaxHeapFreeRatio=10 -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -Xms10m -Xmx192m"),
   725  									sht.ContainerSecurityContext(true),
   726  									tb.VolumeMount("workspace-volume", "/home/jenkins"),
   727  									tb.VolumeMount("docker-daemon", "/var/run/docker.sock"),
   728  									tb.VolumeMount("volume-0", "/root/.m2/"),
   729  									tb.VolumeMount("volume-1", "/home/jenkins/.docker"),
   730  									tb.VolumeMount("volume-2", "/home/jenkins/.gnupg"),
   731  								),
   732  								sht.PipelineVolume(&corev1.Volume{
   733  									Name: "workspace-volume",
   734  									VolumeSource: corev1.VolumeSource{
   735  										EmptyDir: &corev1.EmptyDirVolumeSource{},
   736  									},
   737  								}),
   738  								sht.PipelineVolume(&corev1.Volume{
   739  									Name: "docker-daemon",
   740  									VolumeSource: corev1.VolumeSource{
   741  										HostPath: &corev1.HostPathVolumeSource{
   742  											Path: "/var/run/docker.sock",
   743  										},
   744  									},
   745  								}),
   746  								sht.PipelineVolume(&corev1.Volume{
   747  									Name: "volume-0",
   748  									VolumeSource: corev1.VolumeSource{
   749  										Secret: &corev1.SecretVolumeSource{
   750  											SecretName: "jenkins-maven-settings",
   751  										},
   752  									},
   753  								}),
   754  								sht.PipelineVolume(&corev1.Volume{
   755  									Name: "volume-1",
   756  									VolumeSource: corev1.VolumeSource{
   757  										Secret: &corev1.SecretVolumeSource{
   758  											SecretName: "jenkins-docker-cfg",
   759  										},
   760  									},
   761  								}),
   762  								sht.PipelineVolume(&corev1.Volume{
   763  									Name: "volume-2",
   764  									VolumeSource: corev1.VolumeSource{
   765  										Secret: &corev1.SecretVolumeSource{
   766  											SecretName: "jenkins-release-gpg",
   767  										},
   768  									},
   769  								}),
   770  							),
   771  							sht.PipelineStage("from-build-pack",
   772  								sht.StageAgent("maven"),
   773  								sht.StageDir("/workspace/source"),
   774  								sht.StageStep(sht.StepCmd("jx step git credentials"), sht.StepImage("maven"), sht.StepDir("/workspace/source"),
   775  									sht.StepName("setup-jx-git-credentials")),
   776  								sht.StageStep(sht.StepCmd("echo hi there"), sht.StepImage("maven"), sht.StepDir("/workspace/source"),
   777  									sht.StepName("build-step3")),
   778  								sht.StageStep(sht.StepCmd("mvn clean deploy"), sht.StepImage("maven"), sht.StepDir("/workspace/source"),
   779  									sht.StepName("build-mvn-deploy")),
   780  								sht.StageStep(sht.StepCmd("skaffold version"), sht.StepImage("maven"), sht.StepDir("/workspace/source"),
   781  									sht.StepName("build-skaffold-version")),
   782  								sht.StageStep(sht.StepCmd("/kaniko/executor"), sht.StepDir("/workspace/source"),
   783  									sht.StepImage(jxsyntax.KanikoDockerImage), sht.StepName("build-container-build"),
   784  									sht.StepArg("--cache=true"), sht.StepArg("--cache-dir=/workspace"),
   785  									sht.StepArg("--context=/workspace/source"), sht.StepArg("--dockerfile=/workspace/source/Dockerfile"),
   786  									sht.StepArg("--destination=gcr.io/abayer/jx-demo-qs:${inputs.params.version}"),
   787  									sht.StepArg("--cache-repo=gcr.io//cache")),
   788  								sht.StageStep(sht.StepCmd("jx step post build --image $DOCKER_REGISTRY/$ORG/$APP_NAME:${VERSION}"),
   789  									sht.StepDir("/workspace/source"), sht.StepImage("maven"), sht.StepName("build-post-build")),
   790  								sht.StageStep(sht.StepCmd("echo goodbye"), sht.StepImage("maven"), sht.StepDir("/workspace/source"),
   791  									sht.StepName("build-step8")),
   792  								sht.StageStep(sht.StepCmd("echo wait why am i here"), sht.StepImage("maven"), sht.StepDir("/workspace/source"),
   793  									sht.StepName("build-step9")),
   794  								sht.StageStep(sht.StepCmd("jx step changelog --version v${VERSION}"),
   795  									sht.StepDir("/workspace/source/charts/jx-demo-qs"), sht.StepImage("maven"),
   796  									sht.StepName("promote-changelog")),
   797  								sht.StageStep(sht.StepCmd("jx step helm release"), sht.StepDir("/workspace/source/charts/jx-demo-qs"),
   798  									sht.StepImage("maven"), sht.StepName("promote-helm-release")),
   799  								sht.StageStep(sht.StepCmd("jx promote -b --all-auto --timeout 1h --version ${VERSION}"),
   800  									sht.StepDir("/workspace/source/charts/jx-demo-qs"),
   801  									sht.StepImage("maven"), sht.StepName("promote-jx-promote")),
   802  							),
   803  						),
   804  						SetVersion: &jenkinsfile.PipelineLifecycle{
   805  							Steps: []*jxsyntax.Step{{
   806  								Image: "maven",
   807  								Steps: []*jxsyntax.Step{{
   808  									Comment: "so we can retrieve the version in later steps",
   809  									Name:    "next-version",
   810  									Sh:      "echo \\$(jx-release-version) > VERSION",
   811  									Steps:   []*jxsyntax.Step{},
   812  								}, {
   813  									Name:  "set-version",
   814  									Sh:    "mvn versions:set -DnewVersion=\\$(cat VERSION)",
   815  									Steps: []*jxsyntax.Step{},
   816  								}, {
   817  									Name:  "tag-version",
   818  									Sh:    "jx step tag --version \\$(cat VERSION)",
   819  									Steps: []*jxsyntax.Step{},
   820  								}},
   821  							}},
   822  							PreSteps: []*jxsyntax.Step{},
   823  						},
   824  					},
   825  				},
   826  			},
   827  		},
   828  	}, {
   829  		name: "overrides-with-buildpack-using-jenkins-x-syntax",
   830  		pack: "jx-syntax-in-buildpack",
   831  		// Upper-casing to verify fix for #6983
   832  		repoName:     "Jx-demo-qs",
   833  		organization: "abayer",
   834  		branch:       "master",
   835  		expected: &config.ProjectConfig{
   836  			BuildPack: "jx-syntax-in-buildpack",
   837  			PipelineConfig: &jenkinsfile.PipelineConfig{
   838  				Agent: &jxsyntax.Agent{
   839  					Image: "maven",
   840  					Label: "jenkins-maven",
   841  				},
   842  				Env: []corev1.EnvVar{},
   843  				Pipelines: jenkinsfile.Pipelines{
   844  					Overrides: []*jxsyntax.PipelineOverride{{
   845  						Pipeline: "release",
   846  						Stage:    "build",
   847  						Step: &jxsyntax.Step{
   848  							Command: "echo hi there",
   849  							Name:    "hi-there",
   850  						},
   851  						Name: "flake8",
   852  						Type: &overrideAfter,
   853  					}},
   854  					PullRequest: &jenkinsfile.PipelineLifecycles{
   855  						Pipeline: sht.ParsedPipeline(
   856  							sht.PipelineAgent("maven"),
   857  							sht.PipelineStage("build",
   858  								sht.StageDir("/workspace/source"),
   859  								sht.StageStep(sht.StepCmd("source /root/.bashrc && flake8"), sht.StepImage("maven"),
   860  									sht.StepDir("/workspace/source/jx-demo-qs"), sht.StepName("flake8")),
   861  							),
   862  						),
   863  					},
   864  					Release: &jenkinsfile.PipelineLifecycles{
   865  						Pipeline: sht.ParsedPipeline(
   866  							sht.PipelineAgent("maven"),
   867  							sht.PipelineStage("build",
   868  								sht.StageDir("/workspace/source"),
   869  								sht.StageStep(sht.StepCmd("source /root/.bashrc && flake8"), sht.StepImage("maven"), sht.StepDir("/workspace/source/jx-demo-qs"),
   870  									sht.StepName("flake8")),
   871  								sht.StageStep(sht.StepCmd("echo hi there"), sht.StepName("hi-there")),
   872  							),
   873  							sht.PipelineStage("promote",
   874  								sht.StageDir("/workspace/source/charts/jx-demo-qs"),
   875  								sht.StageStep(sht.StepCmd("jx step changelog --version v${inputs.params.version}"),
   876  									sht.StepName("changelog")),
   877  								sht.StageStep(sht.StepCmd("jx step helm release"),
   878  									sht.StepName("helm-release")),
   879  								sht.StageStep(sht.StepCmd("jx promote -b --all-auto --timeout 1h --version ${inputs.params.version}"),
   880  									sht.StepName("jx-promote"),
   881  									sht.StepDir("/workspace/source"))),
   882  						),
   883  					},
   884  				},
   885  			},
   886  		},
   887  	}}
   888  
   889  	k8sObjects := []runtime.Object{
   890  		&corev1.ConfigMap{
   891  			ObjectMeta: metav1.ObjectMeta{
   892  				Name:      kube.ConfigMapJenkinsDockerRegistry,
   893  				Namespace: "jx",
   894  			},
   895  			Data: map[string]string{
   896  				"docker.registry": "gcr.io",
   897  			},
   898  		},
   899  		// Dummy secrets created for validation purposes
   900  		&corev1.Secret{
   901  			ObjectMeta: metav1.ObjectMeta{
   902  				Name:      "jenkins-docker-cfg",
   903  				Namespace: "jx",
   904  			},
   905  		},
   906  		&corev1.Secret{
   907  			ObjectMeta: metav1.ObjectMeta{
   908  				Name:      "jenkins-maven-settings",
   909  				Namespace: "jx",
   910  			},
   911  		},
   912  		&corev1.Secret{
   913  			ObjectMeta: metav1.ObjectMeta{
   914  				Name:      "jenkins-release-gpg",
   915  				Namespace: "jx",
   916  			},
   917  		},
   918  	}
   919  	jxObjects := []runtime.Object{}
   920  	repoOwnerUUID, err := uuid.NewUUID()
   921  	assert.NoError(t, err)
   922  	repoOwner := repoOwnerUUID.String()
   923  	repoNameUUID, err := uuid.NewUUID()
   924  	assert.NoError(t, err)
   925  	repoName := repoNameUUID.String()
   926  	fakeRepo, _ := gits.NewFakeRepository(repoOwner, repoName, nil, nil)
   927  	fakeGitProvider := gits.NewFakeProvider(fakeRepo)
   928  
   929  	for _, tt := range cases {
   930  		t.Run(tt.name, func(t *testing.T) {
   931  
   932  			caseDir := path.Join(testData, tt.name)
   933  			_, err = os.Stat(caseDir)
   934  			assert.NoError(t, err)
   935  
   936  			projectConfig, projectConfigFile, err := config.LoadProjectConfig(caseDir)
   937  			if err != nil {
   938  				t.Fatalf("Error loading %s/jenkins-x.yml: %s", caseDir, err)
   939  			}
   940  
   941  			createCanonical := &syntax.StepSyntaxEffectiveOptions{
   942  				Pack:         tt.pack,
   943  				CustomEnvs:   tt.customEnvs,
   944  				DefaultImage: "maven",
   945  				KanikoImage:  jxsyntax.KanikoDockerImage,
   946  				UseKaniko:    true,
   947  				PodTemplates: assertLoadPodTemplates(t),
   948  				GitInfo: &gits.GitRepository{
   949  					Host:         "github.com",
   950  					Name:         tt.repoName,
   951  					Organisation: tt.organization,
   952  				},
   953  				VersionResolver: &versionstream.VersionResolver{
   954  					VersionsDir: testVersionsDir,
   955  				},
   956  				SourceName: "source",
   957  				StepOptions: step.StepOptions{
   958  					CommonOptions: &opts.CommonOptions{
   959  						ServiceAccount: tekton.DefaultPipelineSA,
   960  					},
   961  				},
   962  				ValidateInCluster: true,
   963  			}
   964  			testhelpers.ConfigureTestOptionsWithResources(createCanonical.CommonOptions, k8sObjects, jxObjects, gits_test.NewMockGitter(), fakeGitProvider, helm_test.NewMockHelmer(), nil)
   965  
   966  			newConfig, err := createCanonical.CreateEffectivePipeline(packsDir, projectConfig, projectConfigFile, resolver)
   967  			if err != nil {
   968  				t.Fatalf("Error creating canonical pipeline: %s", err)
   969  			}
   970  			if d, _ := kmp.SafeDiff(tt.expected, newConfig, cmpopts.IgnoreFields(corev1.ResourceRequirements{}, "Requests")); d != "" {
   971  				t.Errorf("Generated canonical pipeline does not match expected:\n%s", d)
   972  			}
   973  		})
   974  	}
   975  }
   976  
   977  func assertLoadPodTemplates(t *testing.T) map[string]*corev1.Pod {
   978  	fileName := filepath.Join("..", "create", "test_data", "step_create_task", "PodTemplates.yml")
   979  	if tests.AssertFileExists(t, fileName) {
   980  		configMap := &corev1.ConfigMap{}
   981  		data, err := ioutil.ReadFile(fileName)
   982  		if assert.NoError(t, err, "Failed to load file %s", fileName) {
   983  			err = yaml.Unmarshal(data, configMap)
   984  			if assert.NoError(t, err, "Failed to unmarshall YAML file %s", fileName) {
   985  				podTemplates := make(map[string]*corev1.Pod)
   986  				for k, v := range configMap.Data {
   987  					pod := &corev1.Pod{}
   988  					if v != "" {
   989  						err := yaml.Unmarshal([]byte(v), pod)
   990  						if assert.NoError(t, err, "Failed to parse pod template") {
   991  							podTemplates[k] = pod
   992  						}
   993  					}
   994  				}
   995  				return podTemplates
   996  			}
   997  		}
   998  	}
   999  	return nil
  1000  }