83 lines
3.3 KiB
Groovy
83 lines
3.3 KiB
Groovy
@Library(['jlib']) _
|
|
|
|
node("docker") {
|
|
// Временная метка в логе Jenkins
|
|
timestamps() {
|
|
// Цветные букавы в логе Jenkins
|
|
ansiColor("xterm"){
|
|
// Получаем актуальную версию репы, где лежит пайп
|
|
checkout scm
|
|
|
|
env.stand = env.BRANCH_NAME
|
|
|
|
if (!(stand in ["prod", "test", "dev"])) {
|
|
error("stand не соответствует 'prod', 'test' или 'dev'")
|
|
}
|
|
|
|
stage("Prepare environments") {
|
|
envConfig = "build/vars/build.yaml"
|
|
support.getVarsV2(envConfig)
|
|
|
|
// пока не будет готов отдельный dev стенд
|
|
env.namespace = "${env.namespace}-${stand}"
|
|
env.registryContainerName = "${env.registryContainerName}-${stand}"
|
|
|
|
println "Success prepare"
|
|
}
|
|
|
|
stage("Scan Image") {
|
|
/* Убрал на время для перехода на Helm всех микросервисов
|
|
def scannerHome = tool 'SonarScanner';
|
|
// Волшебный ключ -Dsonar.qualitygate.wait=true
|
|
withCredentials([string(credentialsId: 'sonarqube-access-personal-account-backend', variable: 'tokenAccess')]) {
|
|
sh "${scannerHome}/bin/sonar-scanner -Dsonar.sources=. -Dsonar.projectKey=personal-account-backend -Dsonar.host.url=https://sq.adl.nubes.ru -Dsonar.login=${tokenAccess}"
|
|
}
|
|
*/
|
|
}
|
|
|
|
stage("Build image") {
|
|
println "Start building image ${env.registryContainerName}:${env.version}"
|
|
|
|
app = docker.build("${env.registryContainerName}:${env.version}", "--no-cache -f ./build/Dockerfile .")
|
|
|
|
println "Start uploading image ${env.registryContainerName}:${env.version} to Nexus"
|
|
docker.withRegistry("https://${registryUrl}", "nexus-jenkins-cred") {
|
|
app.push("${env.version}")
|
|
app.push("latest")
|
|
}
|
|
}
|
|
|
|
stage("Update version in Kubernetes") {
|
|
dir ("build") {
|
|
withCredentials([vaultString(credentialsId: "${env.vaultPath}", variable: "pem")]) {
|
|
sh """
|
|
set +x
|
|
echo "${pem}" | base64 -d > auth.config
|
|
set -x
|
|
"""
|
|
}
|
|
|
|
convertJinjaV2("./helm/values.yaml", debug=true)
|
|
|
|
sh """
|
|
helm upgrade --wait \
|
|
--kubeconfig auth.config \
|
|
--install \
|
|
--namespace ${env.namespace} \
|
|
-f ./helm/values.yaml \
|
|
${env.appName} ./helm/
|
|
"""
|
|
|
|
sh "kubectl --kubeconfig=auth.config get pods --namespace ${env.namespace}"
|
|
}
|
|
}
|
|
|
|
println "Success build job. Now start cleanup"
|
|
|
|
cleanWs(
|
|
deleteDirs: true,
|
|
disableDeferredWipeout: true
|
|
)
|
|
}
|
|
}
|
|
} |