68 lines
2.2 KiB
Groovy
68 lines
2.2 KiB
Groovy
#!groovy
|
|
|
|
def image;
|
|
def branchName = "${env.BRANCH_NAME}";
|
|
def branchNameTest = "preprod";
|
|
def branchNameProd = "master";
|
|
def prefixDocker = "test";
|
|
def dockerNginxName = "nginx";
|
|
def dockerAuthName = "auth";
|
|
def dockerSalixName = "salix"
|
|
def dockerClientName = "client"
|
|
def buildNumber = "${env.BUILD_NUMBER}";
|
|
String[] dockers = [dockerNginxName, dockerAuthName, dockerSalixName, dockerClientName];
|
|
|
|
node {
|
|
|
|
if (branchName == branchNameProd)
|
|
prefixDocker = "prod";
|
|
|
|
stage ('Checkout') {
|
|
checkout scm
|
|
}
|
|
|
|
stage ('build Project Salix'){
|
|
sh "gulp build"
|
|
}
|
|
|
|
for (int i = 0; i < dockers.size(); i++)
|
|
{
|
|
def element = dockers[i];
|
|
stage ("docker ${element}")
|
|
{
|
|
stage ("Stopping ${prefixDocker}-${element} actual")
|
|
{
|
|
try
|
|
{
|
|
def returnDocker = sh (script: "docker stop ${prefixDocker}-${element}", returnStdout: true).trim();
|
|
echo "${returnDocker}";
|
|
returnDocker = sh (script: "docker rm ${prefixDocker}-${element}", returnStdout: true).trim();
|
|
echo "${returnDocker}";
|
|
returnDocker = sh (script: "docker -force rmi ${prefixDocker}-${element}:${buildNumber-1}", returnStdout: true).trim();
|
|
echo "${returnDocker}";
|
|
}catch(Exception _){
|
|
echo "Error Stage Stopping"
|
|
}
|
|
}
|
|
stage ("Create Docker Image ${element}") {
|
|
dir("./services/${element}"){
|
|
stage ("Install modules service ${element}"){
|
|
if (fileExists('./package.json'))
|
|
sh "npm i"
|
|
}
|
|
stage("Build image ${element}"){
|
|
image = docker.build("${prefixDocker}-${element}:${buildNumber}", ".")
|
|
}
|
|
}
|
|
}
|
|
stage ("Run Docker ${element}"){
|
|
image.run ("--name ${prefixDocker}-${element}")
|
|
}
|
|
/*
|
|
stage('docker registry'){
|
|
docker.withServer('tcp://harbor.verdnatura.es','docker-registry')
|
|
}
|
|
*/
|
|
}
|
|
}
|
|
} |