generated from gCubeCI/Pipeline-Docker-Template
Merge pull request 'feature/25131' (#6) from feature/25131 into master
Reviewed-on: #6
This commit is contained in:
commit
38f36774aa
|
@ -1,5 +1,6 @@
|
|||
#!groovy
|
||||
import org.yaml.snakeyaml.Yaml
|
||||
import groovy.json.JsonSlurper
|
||||
|
||||
/**
|
||||
* Deploy gCube components on D4Science Infrastructure (dev and preprod environments)
|
||||
|
@ -57,7 +58,7 @@ pipeline {
|
|||
AGENT_ROOT_FOLDER = "${agent_root_folder}"
|
||||
// folder where all the pending deployment will be added
|
||||
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}"
|
||||
// deploy file related to the current pipeline job
|
||||
DEPLOY_FILE = "${PENDING_DEPLOY_FOLDER}deploy.${PIPELINE_BUILD_NUMBER}.csv"
|
||||
|
@ -82,6 +83,8 @@ pipeline {
|
|||
RELEASE_MANAGER_USER='roberto.cirillo'
|
||||
// name of Smartgears distribution group, defined in the yaml file ( only for release deployments)
|
||||
DISTRIBUTION_CATEGORY='Distribution'
|
||||
// name of Portlets group, defined in the yaml file ( only for release deployments)
|
||||
PORTLET_CATEGORY='Portlets'
|
||||
}
|
||||
|
||||
parameters {
|
||||
|
@ -160,7 +163,7 @@ pipeline {
|
|||
}
|
||||
steps {
|
||||
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"
|
||||
touch $DEPLOY_FILE;
|
||||
if grep -q \"\${TRIGGER_JOB}\" \${DEPLOY_FILE}; then
|
||||
|
@ -210,18 +213,18 @@ pipeline {
|
|||
anyOf{
|
||||
triggeredBy 'BuildUpstreamCause'
|
||||
triggeredBy 'UpstreamCause'
|
||||
//added just for testing . To Remove.
|
||||
// added just for testing . To Remove.
|
||||
triggeredBy cause: "UserIdCause", detail: "${RELEASE_MANAGER_USER}"
|
||||
}
|
||||
// we should improve this conditional check
|
||||
// we should improve this conditional check
|
||||
equals(actual: "${params.TRIGGER_JOB}", expected: "${RELEASE_JOB}")
|
||||
}
|
||||
steps {
|
||||
script{
|
||||
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);
|
||||
}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();
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
/* CHECKUP METHODS */
|
||||
|
||||
//Implement a new method in order to check the input parameters
|
||||
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
|
||||
def checkupRelease(String service, String version){
|
||||
sh("""
|
||||
|
@ -311,6 +296,10 @@ def checkupRelease(String service, String version){
|
|||
esac
|
||||
""")
|
||||
}
|
||||
|
||||
|
||||
/* DEPLOY METHODS*/
|
||||
|
||||
//parse all csv files found in the local folder and deploy the components defined inside
|
||||
def parseDeployPendingJobs( def deployFolder){
|
||||
println ("searching files in folder ${deployFolder}");
|
||||
|
@ -331,6 +320,7 @@ def parseDeployPendingJobs( def deployFolder){
|
|||
deployJobs(serviceList.unique())
|
||||
}
|
||||
}
|
||||
|
||||
//Deploy jobs from an input list with the following elements: serviceName,serviceVersion,targetHost. Create a new stage for any job
|
||||
def deployJobs(def 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){
|
||||
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)
|
||||
deployRelease(service[0], service[ 1 ], smartgears);
|
||||
else
|
||||
deployRelease(service[0], service[ 1 ], '');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Run ansible deploy
|
||||
def deploy(String service, String version, String host){
|
||||
def now = new Date();
|
||||
println("Going to deploy the service "+service+" with version: "+version+" on target: "+host);
|
||||
def statusCode = sh( script: "cd ${ANSIBLE_ROOT_FOLDER}/CD;./deployService.sh $service $version $host;", returnStdout: true);
|
||||
sh("""
|
||||
echo " last exit code \$?";
|
||||
""")
|
||||
println("Deploy ended with status: "+statusCode);
|
||||
}
|
||||
// collects all the components defined inside one or more yaml categories matching categoryList
|
||||
|
||||
|
||||
/* DEPLOY RELEASE METHODS*/
|
||||
|
||||
// collects all the components defined inside one or more yaml categories matching categoryList and invoke the deploy
|
||||
def deployRelease(def categoryList, def yaml){
|
||||
def isPortlet= false
|
||||
def releaseList = []
|
||||
def portlets = []
|
||||
String smartgears
|
||||
def categories=categoryList.split(',')
|
||||
yaml.gCube_release.Components.each { group_name, component_list ->
|
||||
|
@ -372,9 +362,16 @@ def deployRelease(def categoryList, def yaml){
|
|||
for ( def category : categories){
|
||||
if("${group_name}" == "$category"){
|
||||
if (category == "${DISTRIBUTION_CATEGORY}"){
|
||||
//searching smartgears-distribution version in Distribution component of defined inside the yaml file
|
||||
def sg= component_list?.collect{ if ("$it.name" == 'smartgears-distribution'){ return "$it.version"; }}
|
||||
//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' || "$it.name" == 'smartgears-distribution-legacy' ){ return "$it.version"; }}
|
||||
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{
|
||||
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