merge and removed spaces

This commit is contained in:
Roberto Cirillo 2022-10-17 10:04:59 +02:00
parent c0cecd9790
commit eb8b09115b
1 changed files with 35 additions and 36 deletions

71
Jenkinsfile vendored
View File

@ -19,12 +19,12 @@ if ("${params.gCube_release_version}" || "${params.RELEASE_URL}"){
//locate the release file //locate the release file
releaseURL = "https://code-repo.d4science.org/gCubeCI/gCubeReleases/raw/branch/master/open/gcube-${gCube_release_version}.yaml" releaseURL = "https://code-repo.d4science.org/gCubeCI/gCubeReleases/raw/branch/master/open/gcube-${gCube_release_version}.yaml"
}else{ }else{
releaseURL = "${params.RELEASE_URL}" releaseURL = "${params.RELEASE_URL}"
} }
//load the release file //load the release file
text = releaseURL.toURL().getText() text = releaseURL.toURL().getText()
//parsing //parsing
yamlConfig = new Yaml().load(text) yamlConfig = new Yaml().load(text)
if (verbose) if (verbose)
println yamlConfig.inspect() println yamlConfig.inspect()
echo "Building gCube v. ${yamlConfig.gCube_release.Version}" echo "Building gCube v. ${yamlConfig.gCube_release.Version}"
@ -55,33 +55,33 @@ pipeline {
environment { environment {
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/CD"
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"
BACKUP_FILE = "${PENDING_DEPLOY_FOLDER}deploy.${PIPELINE_BUILD_NUMBER}.bck" BACKUP_FILE = "${PENDING_DEPLOY_FOLDER}deploy.${PIPELINE_BUILD_NUMBER}.bck"
// deploy folder that contains all the pending jobs associated to the current pipeline execution // deploy folder that contains all the pending jobs associated to the current pipeline execution
DEPLOY_FOLDER= "${WORKSPACE}/CD-${PIPELINE_BUILD_NUMBER}" DEPLOY_FOLDER= "${WORKSPACE}/CD-${PIPELINE_BUILD_NUMBER}"
// artifacts coordinates // artifacts coordinates
TRIGGER_JOB= "${params.TRIGGER_JOB}" TRIGGER_JOB= "${params.TRIGGER_JOB}"
TRIGGER_VERSION= "${params.TRIGGER_VERSION}" TRIGGER_VERSION= "${params.TRIGGER_VERSION}"
TRIGGER_HOST="${params.TRIGGER_HOST}" TRIGGER_HOST="${params.TRIGGER_HOST}"
// enable the ContinuousDeployment if TRUE // enable the ContinuousDeployment if TRUE
TRIGGER_CD="${params.TRIGGER_CD}" TRIGGER_CD="${params.TRIGGER_CD}"
// Useful to identify the remote YAML file // Useful to identify the remote YAML file
GCUBE_RELEASE_NUMBER = "${params.gCube_release_version}" GCUBE_RELEASE_NUMBER = "${params.gCube_release_version}"
//Category name of the components candidates to the remote deployment //Category name of the components candidates to the remote deployment
DEPLOY_CATEGORY="${env.DEPLOY_CATEGORY}" DEPLOY_CATEGORY="${env.DEPLOY_CATEGORY}"
//Job name of the release pipeline //Job name of the release pipeline
RELEASE_JOB='gCubeBuilder' RELEASE_JOB='gCubeBuilder'
//URL to the YAML file. Used alternatively to RELEASE_JOB //URL to the YAML file. Used alternatively to RELEASE_JOB
RELEASE_URL= "${params.RELEASE_URL}" RELEASE_URL= "${params.RELEASE_URL}"
// username of ReleaseManager. Used for limiting the preproduction deployments // username of ReleaseManager. Used for limiting the preproduction deployments
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'
} }
parameters { parameters {
@ -132,11 +132,11 @@ pipeline {
echo 'Cron build enabled. Deploy from system ongoing' echo 'Cron build enabled. Deploy from system ongoing'
script { script {
echo "pipeline was triggered by ${params.TRIGGER_JOB}" echo "pipeline was triggered by ${params.TRIGGER_JOB}"
println("Going to deploy all the pending deployments") println("Going to deploy all the pending deployments")
def deployFolder="CD-${env.BUILD_NUMBER}"; def deployFolder="CD-${env.BUILD_NUMBER}";
parseDeployPendingJobs(deployFolder); parseDeployPendingJobs(deployFolder);
} }
} }
} }
stage('Nothing to do ') { stage('Nothing to do ') {
@ -147,11 +147,10 @@ pipeline {
environment name: 'IS_SCHEDULED', value: 'False' environment name: 'IS_SCHEDULED', value: 'False'
} }
} }
} }
steps { steps {
echo 'Going to sleep' echo 'Going to sleep'
sh ' exit 1; ' sh ' exit 1; '
} }
} }
stage('New pending deploy ') { stage('New pending deploy ') {
@ -172,10 +171,10 @@ pipeline {
echo "component ${TRIGGER_JOB} already added. Nothing to add." echo "component ${TRIGGER_JOB} already added. Nothing to add."
else else
echo "${TRIGGER_JOB},${TRIGGER_VERSION},${TRIGGER_HOST}" >> ${DEPLOY_FILE} echo "${TRIGGER_JOB},${TRIGGER_VERSION},${TRIGGER_HOST}" >> ${DEPLOY_FILE}
fi fi
''' '''
// the following catch give always an error in order to return a feedback UNSTABLE to the final user since the deploy is still not performed. // the following catch give always an error in order to return a feedback UNSTABLE to the final user since the deploy is still not performed.
// Not sure this is the best approach // Not sure this is the best approach
catchError(buildResult: 'UNSTABLE', stageResult: 'UNSTABLE') { catchError(buildResult: 'UNSTABLE', stageResult: 'UNSTABLE') {
sh(""" sh("""
exit 126; exit 126;
@ -193,7 +192,7 @@ pipeline {
triggeredBy 'BuildUpstreamCause' triggeredBy 'BuildUpstreamCause'
triggeredBy 'UpstreamCause' triggeredBy 'UpstreamCause'
} }
expression { params.TRIGGER_JOB != "${RELEASE_JOB}" } expression { params.TRIGGER_JOB != "${RELEASE_JOB}" }
} }
steps { steps {
script{ script{
@ -206,7 +205,7 @@ pipeline {
} }
} }
} }
} }
stage('Deploy from gCubeRelease ') { stage('Deploy from gCubeRelease ') {
@ -214,10 +213,10 @@ pipeline {
anyOf{ anyOf{
triggeredBy 'BuildUpstreamCause' triggeredBy 'BuildUpstreamCause'
triggeredBy 'UpstreamCause' triggeredBy 'UpstreamCause'
//added just for testing . To Remove. //added just for testing . To Remove.
triggeredBy cause: "UserIdCause", detail: "${RELEASE_MANAGER_USER}" 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}") equals(actual: "${params.TRIGGER_JOB}", expected: "${RELEASE_JOB}")
} }
steps { steps {
@ -228,14 +227,14 @@ pipeline {
}else { println ("CATEGORIES NOT FOUND ON YAML FILE. SKIP TO NEXT STAGE");} }else { println ("CATEGORIES NOT FOUND ON YAML FILE. SKIP TO NEXT STAGE");}
} }
} }
} }
stage('Deploy manually ') { stage('Deploy manually ') {
when{ when{
allOf{ allOf{
environment name: 'IS_SCHEDULED', value: 'False'; environment name: 'IS_SCHEDULED', value: 'False';
triggeredBy 'UserIdCause' triggeredBy 'UserIdCause'
} }
expression { params.TRIGGER_JOB != "${RELEASE_JOB}" } expression { params.TRIGGER_JOB != "${RELEASE_JOB}" }
} }
steps { steps {
echo "Cron build disabled. Pipeline executed Manually. New deploy of ${params.TRIGGER_JOB} - ${params.TRIGGER_VERSION} ongoing" echo "Cron build disabled. Pipeline executed Manually. New deploy of ${params.TRIGGER_JOB} - ${params.TRIGGER_VERSION} ongoing"
@ -278,7 +277,7 @@ pipeline {
def deploy(String service, String version, String host){ def deploy(String service, String version, String host){
def now = new Date(); def now = new Date();
println("Going to deploy the service "+service+" with version: "+version+" on target: "+host); println("Going to deploy the service "+service+" with version: "+version+" on target: "+host);
def statusCode = sh( script: "cd $ANSIBLE_ROOT_FOLDER;git pull;./deployService.sh $service $version $host;", returnStdout: true); def statusCode = sh( script: "cd $DEPLOY_ROOT_FOLDER;./deployService.sh $service $version $host;", returnStdout: true);
sh(""" sh("""
echo " last exit code \$?"; echo " last exit code \$?";
""") """)
@ -330,12 +329,12 @@ def parseDeployPendingJobs( def deployFolder){
for (def record : records) { for (def record : records) {
println("Processing record: "+record) println("Processing record: "+record)
serviceList += "${record.get(0)},${record.get(1)},${record.get(2)}"; serviceList += "${record.get(0)},${record.get(1)},${record.get(2)}";
} }
sh "rm ${file.path}" sh "rm ${file.path}"
} }
sh "rm -Rf ${deployFolder}" sh "rm -Rf ${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){
@ -349,7 +348,7 @@ def deployJobs(def serviceList){
} }
} }
} }
} }
//Deploy only release components. All the component are passed as: componentName,componentVersion //Deploy only release components. All the component are passed as: componentName,componentVersion
def deployReleaseJobs(def serviceList, String smartgears){ def deployReleaseJobs(def serviceList, String smartgears){
@ -362,7 +361,7 @@ def deployReleaseJobs(def serviceList, String smartgears){
if (smartgears) if (smartgears)
deployRelease(service[0], service[ 1 ], smartgears); deployRelease(service[0], service[ 1 ], smartgears);
else else
deployRelease(service[0], service[ 1 ], null); deployRelease(service[0], service[ 1 ], null);
} }
} }
} }
@ -376,7 +375,7 @@ def deployRelease(def categoryList, def yaml){
if (categories.contains(group_name)){ if (categories.contains(group_name)){
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 version in Distribution component of 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'){ return "$it.version"; }}
smartgears=(sg !=null ) ? sg[0] : null smartgears=(sg !=null ) ? sg[0] : null
@ -388,5 +387,5 @@ def deployRelease(def categoryList, def yaml){
} }
} }
} }
deployReleaseJobs(releaseList, smartgears); deployReleaseJobs(releaseList, smartgears);
} }