generated from gCubeCI/Pipeline-Docker-Template
feature/25131 #6
|
@ -1,5 +1,6 @@
|
||||||
#!groovy
|
#!groovy
|
||||||
import org.yaml.snakeyaml.Yaml
|
import org.yaml.snakeyaml.Yaml
|
||||||
|
import groovy.json.JsonSlurper
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deploy gCube components on D4Science Infrastructure (dev and preprod environments)
|
* Deploy gCube components on D4Science Infrastructure (dev and preprod environments)
|
||||||
|
@ -57,7 +58,7 @@ pipeline {
|
||||||
AGENT_ROOT_FOLDER = "${agent_root_folder}"
|
AGENT_ROOT_FOLDER = "${agent_root_folder}"
|
||||||
// folder where all the pending deployment will be added
|
// folder where all the pending deployment will be added
|
||||||
PENDING_DEPLOY_FOLDER="${agent_root_folder}/CD/"
|
PENDING_DEPLOY_FOLDER="${agent_root_folder}/CD/"
|
||||||
ANSIBLE_ROOT_FOLDER = "${agent_root_folder}/ansible-repos/ansible-playbooks/d4science-ghn-cluster/CD"
|
ANSIBLE_ROOT_FOLDER = "${agent_root_folder}/ansible-repos/ansible-playbooks/d4science-ghn-cluster"
|
||||||
PIPELINE_BUILD_NUMBER = "${env.BUILD_NUMBER}"
|
PIPELINE_BUILD_NUMBER = "${env.BUILD_NUMBER}"
|
||||||
// deploy file related to the current pipeline job
|
// deploy file related to the current pipeline job
|
||||||
DEPLOY_FILE = "${PENDING_DEPLOY_FOLDER}deploy.${PIPELINE_BUILD_NUMBER}.csv"
|
DEPLOY_FILE = "${PENDING_DEPLOY_FOLDER}deploy.${PIPELINE_BUILD_NUMBER}.csv"
|
||||||
|
@ -82,6 +83,8 @@ pipeline {
|
||||||
RELEASE_MANAGER_USER='roberto.cirillo'
|
RELEASE_MANAGER_USER='roberto.cirillo'
|
||||||
// name of Smartgears distribution group, defined in the yaml file ( only for release deployments)
|
// name of Smartgears distribution group, defined in the yaml file ( only for release deployments)
|
||||||
DISTRIBUTION_CATEGORY='Distribution'
|
DISTRIBUTION_CATEGORY='Distribution'
|
||||||
|
// name of Portlets group, defined in the yaml file ( only for release deployments)
|
||||||
|
PORTLET_CATEGORY='Portlets'
|
||||||
}
|
}
|
||||||
|
|
||||||
parameters {
|
parameters {
|
||||||
|
@ -160,7 +163,7 @@ pipeline {
|
||||||
}
|
}
|
||||||
steps {
|
steps {
|
||||||
sh '''
|
sh '''
|
||||||
echo '\033[31;1;4mNew pending deploy added to the queue/033[0m'
|
echo '\033[31;1;4mNew pending deploy/033[0m'
|
||||||
echo "Cron build enabled. Adding ${TRIGGER_JOB} - ${TRIGGER_VERSION} to the queue"
|
echo "Cron build enabled. Adding ${TRIGGER_JOB} - ${TRIGGER_VERSION} to the queue"
|
||||||
touch $DEPLOY_FILE;
|
touch $DEPLOY_FILE;
|
||||||
if grep -q \"\${TRIGGER_JOB}\" \${DEPLOY_FILE}; then
|
if grep -q \"\${TRIGGER_JOB}\" \${DEPLOY_FILE}; then
|
||||||
|
@ -219,9 +222,9 @@ pipeline {
|
||||||
steps {
|
steps {
|
||||||
script{
|
script{
|
||||||
if("${DEPLOY_CATEGORY}"){
|
if("${DEPLOY_CATEGORY}"){
|
||||||
println("Going to deploy the Release components")
|
echo '\033[31;1;4mGoing to deploy gCube Release \033[0m'
|
||||||
deployRelease("${DEPLOY_CATEGORY}", yamlConfig);
|
deployRelease("${DEPLOY_CATEGORY}", yamlConfig);
|
||||||
}else { println ("CATEGORIES NOT FOUND ON YAML FILE. SKIP TO NEXT STAGE");}
|
}else println ("CATEGORIES NOT FOUND. ENVIRONMENT NOT SET FOR RELEASE DEPLOYMENT. NOTHING TO DO");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -268,16 +271,9 @@ pipeline {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//launch ansible deploy
|
|
||||||
def deploy(String service, String version, String host){
|
|
||||||
def now = new Date();
|
/* CHECKUP METHODS */
|
||||||
println("Going to deploy the service "+service+" with version: "+version+" on target: "+host);
|
|
||||||
def statusCode = sh( script: "cd $ANSIBLE_ROOT_FOLDER;./deployService.sh $service $version $host;", returnStdout: true);
|
|
||||||
sh("""
|
|
||||||
echo " last exit code \$?";
|
|
||||||
""")
|
|
||||||
println("Deploy ended with status: "+statusCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Implement a new method in order to check the input parameters
|
//Implement a new method in order to check the input parameters
|
||||||
def checkup(String service, String version, String host){
|
def checkup(String service, String version, String host){
|
||||||
|
@ -290,17 +286,6 @@ def checkup(String service, String version, String host){
|
||||||
""")
|
""")
|
||||||
}
|
}
|
||||||
|
|
||||||
//launch ansible deploy
|
|
||||||
def deployRelease(String service, String version, String smartgears){
|
|
||||||
def now = new Date();
|
|
||||||
println("Going to deploy the service "+service+" with version: "+version+" on preproduction ");
|
|
||||||
def statusCode = sh( script: "cd $ANSIBLE_ROOT_FOLDER;git pull;./deployPreprodService.sh $service $version $smartgears ;", returnStdout: true);
|
|
||||||
sh("""
|
|
||||||
echo " last exit code \$?";
|
|
||||||
""")
|
|
||||||
println("Deploy ended with status: "+statusCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Implement a new method in order to check the input parameters
|
//Implement a new method in order to check the input parameters
|
||||||
def checkupRelease(String service, String version){
|
def checkupRelease(String service, String version){
|
||||||
sh("""
|
sh("""
|
||||||
|
@ -311,6 +296,10 @@ def checkupRelease(String service, String version){
|
||||||
esac
|
esac
|
||||||
""")
|
""")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* DEPLOY METHODS*/
|
||||||
|
|
||||||
//parse all csv files found in the local folder and deploy the components defined inside
|
//parse all csv files found in the local folder and deploy the components defined inside
|
||||||
def parseDeployPendingJobs( def deployFolder){
|
def parseDeployPendingJobs( def deployFolder){
|
||||||
println ("searching files in folder ${deployFolder}");
|
println ("searching files in folder ${deployFolder}");
|
||||||
|
@ -331,6 +320,7 @@ def parseDeployPendingJobs( def deployFolder){
|
||||||
deployJobs(serviceList.unique())
|
deployJobs(serviceList.unique())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Deploy jobs from an input list with the following elements: serviceName,serviceVersion,targetHost. Create a new stage for any job
|
//Deploy jobs from an input list with the following elements: serviceName,serviceVersion,targetHost. Create a new stage for any job
|
||||||
def deployJobs(def serviceList){
|
def deployJobs(def serviceList){
|
||||||
for (def record : serviceList) {
|
for (def record : serviceList) {
|
||||||
|
@ -345,26 +335,26 @@ def deployJobs(def serviceList){
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
//Deploy only release components. All the component are passed as: componentName,componentVersion
|
|
||||||
def deployReleaseJobs(def serviceList, String smartgears){
|
//Run ansible deploy
|
||||||
println("Going to deploy release components");
|
def deploy(String service, String version, String host){
|
||||||
for (def record : serviceList) {
|
def now = new Date();
|
||||||
service=record.split(",");
|
println("Going to deploy the service "+service+" with version: "+version+" on target: "+host);
|
||||||
stage(service[0]){
|
def statusCode = sh( script: "cd ${ANSIBLE_ROOT_FOLDER}/CD;./deployService.sh $service $version $host;", returnStdout: true);
|
||||||
println("Processing RELEASE deploy: service "+service[ 0 ]+" with version "+service[ 1 ]+" and SG "+smartgears)
|
sh("""
|
||||||
catchError(buildResult: 'UNSTABLE', stageResult: 'FAILURE') {
|
echo " last exit code \$?";
|
||||||
checkupRelease(service[0], service[ 1 ]);
|
""")
|
||||||
if (smartgears)
|
println("Deploy ended with status: "+statusCode);
|
||||||
deployRelease(service[0], service[ 1 ], smartgears);
|
|
||||||
else
|
|
||||||
deployRelease(service[0], service[ 1 ], '');
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
/* DEPLOY RELEASE METHODS*/
|
||||||
// collects all the components defined inside one or more yaml categories matching categoryList
|
|
||||||
|
// collects all the components defined inside one or more yaml categories matching categoryList and invoke the deploy
|
||||||
def deployRelease(def categoryList, def yaml){
|
def deployRelease(def categoryList, def yaml){
|
||||||
|
def isPortlet= false
|
||||||
def releaseList = []
|
def releaseList = []
|
||||||
|
def portlets = []
|
||||||
String smartgears
|
String smartgears
|
||||||
def categories=categoryList.split(',')
|
def categories=categoryList.split(',')
|
||||||
yaml.gCube_release.Components.each { group_name, component_list ->
|
yaml.gCube_release.Components.each { group_name, component_list ->
|
||||||
|
@ -372,9 +362,16 @@ def deployRelease(def categoryList, def yaml){
|
||||||
for ( def category : categories){
|
for ( def category : categories){
|
||||||
if("${group_name}" == "$category"){
|
if("${group_name}" == "$category"){
|
||||||
if (category == "${DISTRIBUTION_CATEGORY}"){
|
if (category == "${DISTRIBUTION_CATEGORY}"){
|
||||||
//searching smartgears-distribution version in Distribution component of defined inside the yaml file
|
//searching smartgears-distribution (os smartgears-distribution-legacy) version in Distribution component defined inside the yaml file
|
||||||
def sg= component_list?.collect{ if ("$it.name" == 'smartgears-distribution'){ return "$it.version"; }}
|
def sg= component_list?.collect{ if ("$it.name" == 'smartgears-distribution' || "$it.name" == 'smartgears-distribution-legacy' ){ return "$it.version"; }}
|
||||||
smartgears=(sg !=null ) ? sg[0] : ''
|
smartgears=(sg !=null ) ? sg[0] : ''
|
||||||
|
}else if (category =="${PORTLET_CATEGORY}"){
|
||||||
|
portlets += component_list?.collect{ if ("${it.group_id}" != "null") return "{\"group_id\": \"$it.group_id\", \"name\": \"$it.name\", \"version\": \"$it.version\", \"extension\": \"war\"} "; else return "{\"name\": \"$it.name\", \"version\": \"$it.version\", \"extension\": \"war\"}"}
|
||||||
|
def jsonContent= "{\"generic_portlets\": "+portlets+"}"
|
||||||
|
echo "json: $jsonContent"
|
||||||
|
writeJSON file: 'portlets.json', json: jsonContent
|
||||||
|
def output = sh(returnStdout: true, returnStdoutTrim: true, script: "mv portlets.json $ANSIBLE_ROOT_FOLDER")
|
||||||
|
isPortlet= true
|
||||||
}else{
|
}else{
|
||||||
releaseList += component_list?.collect {return "$it.name,$it.version" }
|
releaseList += component_list?.collect {return "$it.name,$it.version" }
|
||||||
}
|
}
|
||||||
|
@ -383,5 +380,44 @@ def deployRelease(def categoryList, def yaml){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
deployReleaseJobs(releaseList, smartgears);
|
deployReleaseJobs(releaseList, smartgears, isPortlet);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Deploy only release components, starting from a servicelist. All the component are passed as: componentName,componentVersion
|
||||||
|
def deployReleaseJobs(def serviceList, String smartgears, boolean isPortlet){
|
||||||
|
if (serviceList || isPortlet){
|
||||||
|
println("Going to deploy release components");
|
||||||
|
for (def record : serviceList) {
|
||||||
|
service=record.split(",");
|
||||||
|
stage(service[0]){
|
||||||
|
println("Processing RELEASE deploy: service "+service[ 0 ]+" with version "+service[ 1 ]+" and SG "+smartgears)
|
||||||
|
catchError(buildResult: 'UNSTABLE', stageResult: 'FAILURE') {
|
||||||
|
checkupRelease(service[0], service[ 1 ]);
|
||||||
|
if (smartgears)
|
||||||
|
deployReleaseJob(service[0], service[ 1 ], smartgears);
|
||||||
|
else
|
||||||
|
deployReleaseJob(service[0], service[ 1 ], '');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isPortlet){
|
||||||
|
deployReleaseJob('generic-portlet', '','');
|
||||||
|
}
|
||||||
|
|
||||||
|
}else{
|
||||||
|
println("Release components not found. Skip this stage");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//Run ansible deploy related to a single service
|
||||||
|
def deployReleaseJob(String service, String version, String smartgears){
|
||||||
|
def now = new Date();
|
||||||
|
println("Going to deploy the service "+service+" with version: "+version+" on preproduction ");
|
||||||
|
def statusCode = sh( script: "cd ${ANSIBLE_ROOT_FOLDER}/CD;git pull;./deployPreprodService.sh $service $version $smartgears ;", returnStdout: true);
|
||||||
|
sh("""
|
||||||
|
echo " last exit code \$?";
|
||||||
|
""")
|
||||||
|
println("Deploy ended with status: "+statusCode);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue