void processHelmfile()

in stages/BuildDockerfileImageHelm.groovy [37:108]


    void processHelmfile(context, def helmfile) {
        def helmfileYAML = script.readYaml file: helmfile
        def repositoryPath, gitCredentialsId, imageURL

        helmfileYAML.releases.eachWithIndex { release, releaseIndex ->
            script.println "Processing release: ${release.name}"
            if (release.labels.type == 'remote') {
                def gitBranch = (release.version == 'master' || release.labels.isbranch == true) ? release.version : 'build/' + release.version
                repositoryPath = release.labels.path.endsWith('/') || release.labels.path == '' ? release.labels.path + release.name + '.git' : release.labels.path + '/' + release.name + '.git'
                gitCredentialsId = release.labels.repoURL.contains('gitbud.epam.com') ? 'git-epam-ciuser-sshkey' : 'gerrit-ciuser-sshkey'

                if (stageCRJSON.dockerimage."${release.name}-image") {
                    if (stageCRJSON.dockerimage."${release.name}-image".image.startsWith("${script.env.dockerProxyRegistry}/${script.env.ciProject}/")) {
                        imageURL = stageCRJSON.dockerimage."${release.name}-image".image - "${script.env.dockerProxyRegistry}/${script.env.ciProject}/"
                    }
                    else {
                        imageURL = stageCRJSON.dockerimage."${release.name}-image".image - "${script.env.dockerProxyRegistry}/"
                    }
                    imageURL = imageURL.replaceAll(/(.*):.*/,'\$1')
                    helmfileYAML.releases[releaseIndex].values.add([image: [name: '{{ env "edpComponentDockerRegistryUrl" }}/{{ env "globalEDPProject" }}/' + imageURL, version: helmfileYAML.releases[releaseIndex].version]])
                }

                helmfileYAML.releases[releaseIndex].remove('repoURL')
                helmfileYAML.releases[releaseIndex].remove('stream')
                helmfileYAML.releases[releaseIndex].remove('type')
                helmfileYAML.releases[releaseIndex].labels.branch = release.version

                // version must be specified
                if (!release.version) {
                    throw new Exception("${release.name} version is not specified")
                }

                if (!script.fileExists("repositories/${repositoryPath}")) {
                    script.dir("repositories/${repositoryPath}") {
                        script.checkout([$class                           : 'GitSCM', branches: [[name: gitBranch]],
                                         doGenerateSubmoduleConfigurations: false, extensions: [],
                                         submoduleCfg                     : [],
                                         userRemoteConfigs                : [[credentialsId: gitCredentialsId,
                                                                              url          : release.labels.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 ${release.version}")
                    }
                } else if (!script.sh(script: "cd repositories/${repositoryPath}; git branch -a | grep ${release.version} &2>1", returnStdout: true)) {
                    script.println "repositoryPath: ${repositoryPath}"
                    script.dir("${context.workDir}/tmp/${repositoryPath}") {
                        script.checkout([$class                           : 'GitSCM', branches: [[name: gitBranch]],
                                         doGenerateSubmoduleConfigurations: false, extensions: [],
                                         submoduleCfg                     : [],
                                         userRemoteConfigs                : [[credentialsId: gitCredentialsId,
                                                                              url          : release.labels.repoURL]]])
                        script.sh("rm -rf .git; rm -f .gitignore .helmignore")
                    }
                    script.dir("repositories/${repositoryPath}") {
                        script.sh("git checkout -f -B ${release.version}")
                        script.sh("mkdir -p ${context.workDir}/tmp/${release.name}_git; mv .git ${context.workDir}/tmp/${release.name}_git/; rm -rf ./*; mv ${context.workDir}/tmp/${release.name}_git/.git .git")
                        script.sh("scp -rp ${context.workDir}/tmp/${repositoryPath}/* ./")
                        script.sh("git add --all; git commit -a -m 'Added branch ${release.version}'")
                    }
                }
                else {
                    script.println "Repository repositories/${repositoryPath} and branch ${release.version} already exists"
                }
            }
            if (release.name == 'codebases' || release.name == 'registry-configuration') {
                helmfileYAML.releases[releaseIndex].values.add([codebases: [registryRegulations: [ registryRegulationsRepoVersion: stageCRJSON.gitsources.'empty-template-registry-regulation'.version]]])
                helmfileYAML.releases[releaseIndex].values.add([codebases: [registryRegulations: [ historyExcerptorRepoVersion: stageCRJSON.gitsources.'history-excerptor-chart'.version]]])
            }
        }

        script.writeYaml data: helmfileYAML, file: helmfile, overwrite: true
        script.sh "cat ${helmfile}"
    }