in vars/Build.groovy [27:111]
def call() {
def context = [:]
node("master") {
stage("Init") {
context.platform = new PlatformFactory().getPlatformImpl(this)
context.job = new Job(JobType.BUILD.value, context.platform, this)
context.job.init()
println("[JENKINS][DEBUG] Created object job with type - ${context.job.type}")
context.git = new GitInfo(context.job, context.platform, this)
context.git.init()
context.nexus = new Nexus(context.job, context.platform, this)
context.nexus.init()
context.sonar = new Sonar(context.job, context.platform, this)
context.sonar.init()
context.codebase = new Codebase(context.job, context.git.project, context.platform, this)
context.codebase.setConfig(context.git.autouser, context.git.host, context.git.sshPort, context.git.project, context.git.repositoryRelativePath)
context.factory = new StageFactory(script: this)
context.factory.loadEdpStages().each() { context.factory.add(it) }
context.factory.loadCustomStagesFromLib().each() { context.factory.add(it) }
context.factory.loadCustomStages("${WORKSPACE.replaceAll("@.*", "")}@script/stages").each() { context.factory.add(it) }
context.job.printDebugInfo(context)
println("[JENKINS][DEBUG] Codebase config - ${context.codebase.config}")
if (context.codebase.config.versioningType == "edp") {
def codebaseBranch = getCodebaseBranch(context.codebase.config.codebase_branch, context.git.branch)
def build = codebaseBranch.build_number.toInteger()
def version = codebaseBranch.version
def currentBuildNumber = ++build
def isReleaseBranch = codebaseBranch.release
context.codebase.setVersions(version, currentBuildNumber, "${version}.${currentBuildNumber}", "${version}.${currentBuildNumber}", isReleaseBranch)
context.job.setDisplayName("${context.codebase.version}")
} else {
context.job.setDisplayName("${currentBuild.number}-${context.git.displayBranch}")
}
context.job.setDescription("Name: ${context.codebase.config.name}\r\nLanguage: ${context.codebase.config.language}" +
"\r\nBuild tool: ${context.codebase.config.build_tool}\r\nFramework: ${context.codebase.config.framework}")
}
}
node(context.codebase.config.jenkinsSlave.toLowerCase()) {
try {
context.workDir = new File("/tmp/${RandomStringUtils.random(10, true, true)}")
context.workDir.deleteDir()
context.buildTool = new BuildToolFactory().getBuildToolImpl(context.codebase.config.build_tool, this, context.nexus, context.job)
context.buildTool.init()
context.job.stages.each() { stage ->
if (stage instanceof ArrayList) {
def parallelStages = [:]
stage.each() { parallelStage ->
parallelStages["${parallelStage.name}"] = {
context.job.runStage(parallelStage.name, context)
}
}
parallel parallelStages
} else {
context.job.runStage(stage.name, context)
}
}
} catch (Exception ex) {
println "[JENKINS][ERROR] Trace: ${ex.getStackTrace().collect { it.toString() }.join('\n')}"
println("[JENKINS][ERROR] Build pipeline has failed. Reason - ${ex}")
currentBuild.setResult('FAILED')
} finally {
if (context.codebase.config.versioningType == "edp" && currentBuild.currentResult == 'SUCCESS') {
def codebaseBranchesName = "codebasebranches.${context.job.crApiVersion}.edp.epam.com"
sh """
kubectl patch ${codebaseBranchesName} ${context.codebase.config.name}-${
context.git.branch.replaceAll(/\//, "-")
} --subresource=status --type=merge -p '{\"status\": {\"lastSuccessfulBuild\": "${context.codebase.currentBuildNumber}"}}'
"""
}
}
}
}