void run()

in stages/BuildDockerfileImageHelm.groovy [110:223]


    void run(context) {
        if (!script.fileExists("${context.workDir}/Dockerfile")) {
            script.error "[JENKINS][ERROR] There is no Dockerfile in the root directory of the project ${context.codebase.name}. "
        }

        def resultTag
        script.openshift.withCluster() {
            script.openshift.withProject() {
                script.dir("${context.workDir}") {
                    script.env.dockerRegistryHost = context.platform.getJsonPathValue("edpcomponent", "docker-registry", ".spec.url")
                    script.env.dockerProxyRegistry = context.job.dnsWildcard.startsWith("apps.cicd") ? 'nexus-docker-registry.' + context.job.dnsWildcard : ''
                    script.env.ciProject = context.job.dnsWildcard.startsWith("apps.cicd") ? 'mdtu-ddm-edp-cicd' : context.job.edpName

                    script.sh "git config --global user.email 'admin@example.com'"

                    if (!script.env.dockerRegistryHost) {
                        script.error("[JENKINS][ERROR] Couldn't get docker registry server")
                    }

                    def buildconfigName = "${context.codebase.name}-dockerfile-${context.git.branch.replaceAll("[^\\p{L}\\p{Nd}]+", "-")}"
                    def outputImagestreamName = "${context.codebase.name}-${context.git.branch.replaceAll("[^\\p{L}\\p{Nd}]+", "-")}"
                    def imageRepository = "${script.env.dockerRegistryHost}/${context.job.ciProject}/${outputImagestreamName}"

                    context.codebase.imageBuildArgs.push("--name=${buildconfigName}")

                    def imageUrl = "${imageRepository}:${context.codebase.isTag}"
                    context.codebase.imageBuildArgs.push("--to=${imageUrl}")
                    context.codebase.imageBuildArgs.push("--binary=true")
                    context.codebase.imageBuildArgs.push("--to-docker=true")
                    context.codebase.imageBuildArgs.push("--push-secret=nexus-docker-registry")

                    createOrUpdateBuildConfig(context.codebase, buildconfigName, imageUrl)

                    def repositoryPath, gitCredentialsId

                    stageCRJSON = script.readJSON(file: "properties/stageCR.json")

                    stageCRJSON.gitsources.each { component, value ->
                        repositoryPath = value.path.endsWith('/') || value.path == '' ? value.path + component + '.git' : value.path + '/' + component + '.git'
                        gitCredentialsId = value.repoURL.contains('gitbud.epam.com') ? 'git-epam-ciuser-sshkey' : 'gerrit-ciuser-sshkey'
                        script.dir("repositories/${repositoryPath}") {
                            script.checkout([$class                           : 'GitSCM', branches: [[name: value.version]],
                                             doGenerateSubmoduleConfigurations: false, extensions: [],
                                             submoduleCfg                     : [],
                                             userRemoteConfigs                : [[credentialsId: gitCredentialsId,
                                                                                  url          : value.repoURL]]])

                            script.sh("rm -rf .git; rm -f .gitignore .helmignore; git init; git add --all; git commit -a -m 'Repo init'")
                            script.sh("git checkout -f -B ${value.version}")
                        }
                    }


                    // template release components
                    ArrayList listOfTemplates = script.sh(script: """ ls -1 ${context.workDir}/resources/repositories/templates """, returnStdout: true).tokenize('\n')
                    listOfTemplates.each {
                        processHelmfile(context, "${context.workDir}/resources/repositories/templates/${it}/deploy-templates/helmfile.yaml")
                    }

                    // cluster-mgmt.git
                    processHelmfile(context, "${context.workDir}/resources/repositories/cluster-mgmt.git/properties/cluster-mgmt.yaml")
                    processHelmfile(context, "${context.workDir}/resources/repositories/cluster-mgmt.git/deploy-templates/helmfile.yaml")

                    // user-management.git
                    processHelmfile(context, "${context.workDir}/repositories/components/infra/user-management.git/deploy-templates/helmfile.yaml")

                    // external-integration-mocks.git
                    processHelmfile(context, "${context.workDir}/repositories/components/infra/external-integration-mocks.git/deploy-templates/helmfile.yaml")

                    // cluster-kafka-operator.git
                    processHelmfile(context, "${context.workDir}/repositories/components/infra/cluster-kafka-operator.git/deploy-templates/helmfile.yaml")

                    // create bare git repos from templates
                    script.dir("resources/repositories") {
                        def templateRepo = script.sh(script: "find ./ -name '*.git' -type d", returnStdout: true).tokenize('\n')
                        // TODO: adding datamock.git needed for registry
                        templateRepo.add('datamock.git')

                        templateRepo.each {
                            script.dir(it) {
                                script.sh "git init; git add --all; git commit -a --allow-empty -m 'Repo init'"
                                script.sh("git checkout -f -B ${context.codebase.version}")
                                script.sh("git checkout -f -B master")
                            }
                            script.sh "git clone --bare ${it} ${context.workDir}/git/${it}"
                        }
                    }

                    script.dir('repositories') {
                        script.sh(script: "find . -name .git -type d -prune -exec dirname {} \\;", returnStdout: true).tokenize('\n').each {
                            script.dir(it) {
                                script.sh("git commit --allow-empty -a -m 'updated properties'")
                                script.sh("git checkout -f -B master")
                            }
                            script.sh "git clone --bare ${it} ${context.workDir}/git/${it}"
                        }
                    }

                    script.sh "tar -cf ${context.codebase.name}.tar Dockerfile git/* resources/*"

                    def buildResult = script.openshift.selector(buildConfigApi, "${buildconfigName}").startBuild(
                            "--from-archive=${context.codebase.name}.tar",
                            "--wait=true")
                    resultTag = buildResult.object().status.output.to.imageDigest

                    script.println("[JENKINS][DEBUG] Build config ${context.codebase.name} with result " +
                            "${buildconfigName}:${resultTag} has been completed")

                    new CodebaseImageStreams(context, script)
                            .UpdateOrCreateCodebaseImageStream(outputImagestreamName, imageRepository, context.codebase.isTag)
                }
            }
        }
    }