in src/com/epam/digital/data/platform/pipelines/stages/impl/general/BuildDockerfileImage.groovy [30:73]
void run() {
context.logger.debug("Get version from pom.xml")
String version = context.script.readMavenPom(file: "pom.xml").version
context.codebase.setImageTag(version)
context.logger.debug("Version from pom.xml: ${version}")
String imageVersion = context.codebase.version.replaceAll("\\.", "-")
context.codebase.setImageName("$context.codebase.imageName-$imageVersion")
def response = context.script.httpRequest url: "http://nexus:8081/nexus/repository/docker-registry/v2/$context.namespace/$context.codebase.imageName/manifests/$context.codebase.imageTag",
authentication: 'nexus-ci.user',
httpMode: 'GET',
consoleLogResponseBody: context.logLevel == "DEBUG",
quiet: context.logLevel != "DEBUG",
validResponseCodes: "200,404"
if ((response.getStatus() == 404) || (response.getStatus() == 200)) {
if (context.script.fileExists("${context.workDir}/Dockerfile")) {
String globalNexusNamespace = context.dnsWildcard.startsWith("apps.cicd") ?
'mdtu-ddm-edp-cicd' : 'control-plane'
String dockerFileSourcePath = "${context.workDir}/Dockerfile"
String dockerFileDestPath = "${context.workDir}/Dockerfile"
updateDockerfile(dockerFileSourcePath, context.dockerRegistry.proxyHost, globalNexusNamespace,
dockerFileDestPath)
} else {
context.script.error "There is no Dockerfile in the root directory of the project " +
"${context.codebase.name}. "
}
if (context.platform.checkObjectExists(BUILD_CONFIG_API, context.codebase.buildConfigName)) {
context.logger.info("Updating build config ${context.codebase.buildConfigName}")
context.platform.patch(BUILD_CONFIG_API, context.codebase.buildConfigName,
"\"{\\\"spec\\\":{\\\"output\\\":" +
"{\\\"to\\\":{\\\"name\\\":\\\"${context.codebase.imageUrl}\\\"}}}}\"")
} else {
createBuildConfig()
}
context.logger.info("Start build of ${context.codebase.imageUrl} image")
String tarArchive = "${context.codebase.name}.tar"
context.script.sh(script: "tar -cf ${tarArchive} Dockerfile src pom.xml settings.xml; " +
"oc start-build ${context.codebase.buildConfigName} --from-archive=${tarArchive} --wait=true")
} else {
createBuildConfig()
}
}