Compare commits

..

87 Commits

Author SHA1 Message Date
Roberto Cirillo 5e84d57f91 Update Jenkinsfile
change email address to jenkinsbuilds@d4science.org
2024-11-28 12:25:26 +01:00
Roberto Cirillo 545ec46752 remove hardcoded dry-run 2024-11-11 11:16:06 +01:00
Roberto Cirillo 6a162840a4 hardcoded dryrun mode 2024-11-11 10:01:50 +01:00
Roberto Cirillo 4a89d6b448 Update README.md
fix readme
2024-11-07 10:01:16 +01:00
Roberto Cirillo d678d87ec8 fix checkup method exit condition 2024-11-05 15:06:20 +01:00
Roberto Cirillo 78904c0793 fix checkup method exit condition 2024-11-05 14:43:42 +01:00
Roberto Cirillo fea4741152 Merge pull request 'bug/28263' (#9) from bug/28263 into master
Reviewed-on: #9
2024-11-04 10:02:09 +01:00
Roberto Cirillo c9af197c68 split catcherror in order to manage differents cases 2024-10-30 15:46:28 +01:00
Roberto Cirillo 4ab3535e90 removed catch error inside deployJobs 2024-10-30 14:55:35 +01:00
Roberto Cirillo ad9f9382fb add status check on release deploy groovy script 2024-10-30 12:39:33 +01:00
Roberto Cirillo 5bbf75f4fd small change 2024-10-30 11:45:39 +01:00
Roberto Cirillo 8ae9a74ff0 small change 2024-10-30 11:43:54 +01:00
Roberto Cirillo cf0ea75460 add exit to deploy script 2024-10-30 11:31:43 +01:00
Roberto Cirillo 4728bd16b9 small fix 2024-10-30 10:44:48 +01:00
Roberto Cirillo ecc8b71cbe add dir function for testing 2024-10-30 10:41:26 +01:00
Roberto Cirillo ceaa196895 small fix 2024-10-30 10:33:40 +01:00
Roberto Cirillo ec7ae82e9b fix print message 2024-10-30 10:30:49 +01:00
Roberto Cirillo d56d1a693e add check on statusCode 2024-10-30 10:18:15 +01:00
Roberto Cirillo dbee8ad96c Merge pull request 'set ANSIBLE_ROOT_FOLDER value to d4science-smartgears-services/' (#8) from feature/27892 into master
Reviewed-on: #8
2024-09-18 15:48:02 +02:00
Roberto Cirillo 39e1daf6c7 set ANSIBLE_ROOT_FOLDER value to d4science-smartgears-services/ 2024-07-25 11:49:54 +02:00
Roberto Cirillo 693c528411 add foo input parameter 2024-02-23 16:06:41 +01:00
Roberto Cirillo 8a95929a8a Merge pull request 'add portlets stage when needed' (#7) from feature/25131 into master
Reviewed-on: #7
2023-09-07 15:02:00 +02:00
Roberto Cirillo c6832781d6 add portlets stage when needed 2023-09-07 15:00:57 +02:00
Roberto Cirillo 38f36774aa Merge pull request 'feature/25131' (#6) from feature/25131 into master
Reviewed-on: #6
2023-09-07 14:56:00 +02:00
Roberto Cirillo 951d53cef2 managed the smartgears-distribution-legacy component just in case it is
present on release file
2023-09-07 12:21:14 +02:00
Roberto Cirillo 4adce129eb Update 'README.md'
fix readme
2023-07-11 17:00:28 +02:00
Roberto Cirillo 7583e98a94 Update 'README.md'
update readme
2023-07-11 16:59:09 +02:00
Roberto Cirillo 3e4029c597 Merge branch 'master' of https://code-repo.d4science.org/gCubeCI/gCubeDeployer 2023-07-11 16:48:10 +02:00
Roberto Cirillo 8ae88c9d04 add new screeeshot in folder images 2023-07-11 16:47:00 +02:00
Roberto Cirillo 974a264b32 fix collection condition 2023-06-16 09:44:32 +02:00
Roberto Cirillo f823ac8d19 fix collection 2023-06-16 09:41:08 +02:00
Roberto Cirillo 0ec2f9b56d fix collection 2023-06-16 09:39:37 +02:00
Roberto Cirillo 30f75a203e fix remove unset group 2023-06-16 09:22:28 +02:00
Roberto Cirillo 87931065a3 try to remove the null values 2023-06-16 09:16:19 +02:00
Roberto Cirillo 2fbc25b0fd fix group field name 2023-06-16 09:12:28 +02:00
Roberto Cirillo a52265bcdd remove default from group_id field 2023-06-16 09:04:06 +02:00
Roberto Cirillo dd691f73c9 add check on group_id just for test 2023-06-16 08:56:40 +02:00
Roberto Cirillo 48e2c3fd47 fix json syntax 2023-06-15 17:12:50 +02:00
Roberto Cirillo ba88a51028 add brackets to json creation string 2023-06-15 16:13:56 +02:00
Roberto Cirillo 1609eb2c1e fix again json syntax 2023-06-15 16:07:00 +02:00
Roberto Cirillo 1a63a95de4 try to remove brackets 2023-06-15 15:58:52 +02:00
Roberto Cirillo d55c3c728f add json slurper import 2023-06-15 15:45:55 +02:00
Roberto Cirillo 77cf75579c check json slurper method 2023-06-15 15:42:29 +02:00
Roberto Cirillo 203967e625 restore old variable for debugging 2023-06-15 15:28:26 +02:00
Roberto Cirillo f9c0476638 fix variable name 2023-06-15 15:22:52 +02:00
Roberto Cirillo 14dcf64e6d fix json 2023-06-15 15:15:32 +02:00
Roberto Cirillo 12be87c118 fix json file generation 2023-06-15 15:04:07 +02:00
Roberto Cirillo 6ada59467f fix json file 2023-06-15 14:54:23 +02:00
Roberto Cirillo 8e4a4ea249 change ANSIBLE_ROOT_FOLDER value 2023-06-15 12:38:46 +02:00
Roberto Cirillo ce2beba794 fix deploy condition 2023-06-15 12:15:15 +02:00
Roberto Cirillo 9d7fbced7f add portlets to the deploy job. first attempt 2023-06-15 12:02:55 +02:00
Roberto Cirillo b86ed090b9 fix some comments 2023-06-15 11:35:11 +02:00
Roberto Cirillo b0e4dd25be small changes 2023-06-15 11:27:17 +02:00
Roberto Cirillo eacc8c2d97 move json file in the right location 2023-06-14 17:04:13 +02:00
Roberto Cirillo b26d4cde46 fix portlet collection 2023-06-14 15:29:48 +02:00
Roberto Cirillo 65d5636324 fix portlet collection method 2023-06-14 15:24:58 +02:00
Roberto Cirillo 045849a57b add new colored print 2023-06-14 15:17:44 +02:00
Roberto Cirillo 7f786fbbe7 add check on release components 2023-06-14 14:59:34 +02:00
Roberto Cirillo 195ad81f65 add condition on Portlet category related to Release deployment 2023-06-14 10:51:01 +02:00
Roberto Cirillo 942176c290 hotfix on smartgears distribution upgrade on release build 2023-05-17 10:10:54 +02:00
Roberto Cirillo 6a8a52bbd3 hotfix deploy release script 2023-05-17 09:52:21 +02:00
Roberto Cirillo 5b236a4f63 update release job 2023-05-17 09:15:35 +02:00
Roberto Cirillo 6f847cecf7 swith release job to gCubeBuilder_branch 2023-05-09 10:58:48 +02:00
Roberto Cirillo c6cccec47d Merge branch 'master' of https://code-repo.d4science.org/gCubeCI/gCubeDeployer.git 2023-05-09 10:21:07 +02:00
Roberto Cirillo e70250bfdd add new print 2023-05-09 10:20:49 +02:00
Roberto Cirillo 8c37113fcb Merge pull request 'testColor' (#5) from testColor into master
Reviewed-on: #5
2023-04-26 15:58:59 +02:00
Roberto Cirillo d2ccba5770 fix echo 2023-04-26 15:55:34 +02:00
Roberto Cirillo 5f9f635a61 fix echo 2023-04-26 15:29:59 +02:00
Roberto Cirillo 3f2fb836c0 add some comments 2023-04-26 15:25:14 +02:00
Roberto Cirillo 2606032208 deployJob stage: set to unstable if ansible fail 2023-03-08 17:18:18 +01:00
Roberto Cirillo 2d35aba7d5 Update 'Jenkinsfile'
fix ansiColor syntax
2022-12-13 14:31:36 +01:00
Roberto Cirillo 8333695959 replace DEPLOY_ROOT_FOLDER var with ANSIBLE_ROOT_FOLDER 2022-10-24 14:41:28 +02:00
Roberto Cirillo 8076da5291 remove unused variable 2022-10-18 10:53:42 +02:00
Roberto Cirillo 59c1d9741a set RELEASE_JOB name to Pipeline-gCubeBuilder 2022-10-18 10:49:34 +02:00
Roberto Cirillo 0c3d39c63d remove exit 1 from Nothing to do stage 2022-10-17 16:32:53 +02:00
Roberto Cirillo f48df8bc6a add Environment variable section to README.md 2022-10-17 10:36:27 +02:00
Roberto Cirillo eb8b09115b merge and removed spaces 2022-10-17 10:04:59 +02:00
Roberto Cirillo c0cecd9790 Delete 'images/FlowChartgCubeDeployer.png' 2022-10-13 17:35:13 +02:00
Roberto Cirillo 6974b8ee91 update flowchart 2022-10-13 17:34:51 +02:00
Roberto Cirillo 2c859c8db7 update flowchart 2022-10-13 17:27:19 +02:00
Roberto Cirillo 0d3a7ae517 Merge branch 'master' of https://code-repo.d4science.org/gCubeCI/gCubeDeployer 2022-10-13 17:22:50 +02:00
Roberto Cirillo 6e4225dc3f add flowchart image 2022-10-13 17:21:46 +02:00
Roberto Cirillo 9f7aa7cd4e Update 'README.md'
add flowchart link
2022-10-13 17:20:51 +02:00
Roberto Cirillo f76b12e52e Update 'README.md'
removed FlowChart
2022-10-13 15:50:28 +02:00
Roberto Cirillo 9527de940c Update 'README.md'
try to add flowchart
2022-10-13 15:48:14 +02:00
Roberto Cirillo e1b08e8cc3 fix readme 2022-10-13 11:26:18 +02:00
Roberto Cirillo 599ab1ebf7 Replace IS_SCHEDULED_TEST with IS_SCHEDULED var 2022-10-13 11:24:24 +02:00
7 changed files with 610 additions and 113 deletions

232
Jenkinsfile vendored
View File

@ -1,8 +1,9 @@
#!groovy #!groovy
import org.yaml.snakeyaml.Yaml import org.yaml.snakeyaml.Yaml
import groovy.json.JsonSlurper
/** /**
* Deploy gCube components on D4Science Infrastructure (dev-only) * Deploy gCube components on D4Science Infrastructure (dev and preprod environments)
* *
* Roberto Cirillo (ISTI-CNR) * Roberto Cirillo (ISTI-CNR)
*/ */
@ -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-smartgears-services"
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"
@ -70,18 +71,22 @@ pipeline {
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}"
// generic parameter that can be passed to the ansible job
TRIGGER_FOO="${params.TRIGGER_FOO}"
// 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='Pipeline-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='giancarlo.panichi'
// 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 {
@ -97,12 +102,12 @@ pipeline {
booleanParam(name: 'TRIGGER_CD', booleanParam(name: 'TRIGGER_CD',
defaultValue: true, defaultValue: true,
description: 'Set to false to avoid current deploy') description: 'Set to false to avoid current deploy')
string(name: 'TRIGGER_FOO',
defaultValue: '',
description: 'Additional parameter to pass to the ansible job. Leave blank if not used')
string(name: 'gCube_release_version', string(name: 'gCube_release_version',
defaultValue: '', defaultValue: '',
description: 'The number of the gCube release. Leave blank if executed outside gCube release.') description: 'The number of the current gCube release. Leave blank if executed outside gCube release.')
string(name: 'report_number',
defaultValue: '',
description: 'The build report number on Git to pull the notes. Leave blank if executed outside gCube release.')
string(name: 'RELEASE_URL', string(name: 'RELEASE_URL',
defaultValue: '', defaultValue: '',
description: 'URL to the yaml file. Leave blank if executed outside gCube release.') description: 'URL to the yaml file. Leave blank if executed outside gCube release.')
@ -124,12 +129,12 @@ pipeline {
anyOf{ anyOf{
allOf{ allOf{
triggeredBy 'TimerTrigger' triggeredBy 'TimerTrigger'
environment name: 'IS_SCHEDULED_TEST', value: 'True' environment name: 'IS_SCHEDULED', value: 'True'
} }
} }
} }
steps { steps {
echo 'Cron build enabled. Deploy from system ongoing' echo 'Cron build enabled. \033[31;1;4mDeploy from system ongoing\033[0m'
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")
@ -141,22 +146,19 @@ pipeline {
} }
stage('Nothing to do ') { stage('Nothing to do ') {
when{ when{
anyOf{ allOf{
allOf{ triggeredBy 'TimerTrigger'
triggeredBy 'TimerTrigger' environment name: 'IS_SCHEDULED', value: 'False'
environment name: 'IS_SCHEDULED_TEST', value: 'False'
}
} }
} }
steps { steps {
echo 'Going to sleep' echo '\033[31;1;4mGoing to sleep\033[0m'
sh ' exit 1; ' sh ' exit 0; '
} }
} }
stage('New pending deploy ') { stage('New pending deploy ') {
when{ when{
environment name: 'IS_SCHEDULED_TEST', value: 'True' environment name: 'IS_SCHEDULED', value: 'True'
anyOf{ anyOf{
triggeredBy 'BuildUpstreamCause' triggeredBy 'BuildUpstreamCause'
triggeredBy 'UpstreamCause' triggeredBy 'UpstreamCause'
@ -166,7 +168,8 @@ pipeline {
} }
steps { steps {
sh ''' sh '''
echo "Cron build enabled. New deploy of ${TRIGGER_JOB} - ${TRIGGER_VERSION} will be added to the pending deploy file" echo '\033[31;1;4mNew pending deploy/033[0m'
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
echo "component ${TRIGGER_JOB} already added. Nothing to add." echo "component ${TRIGGER_JOB} already added. Nothing to add."
@ -185,7 +188,7 @@ pipeline {
} }
stage('Deploy from job ') { stage('Deploy from job ') {
when{ when{
environment name: 'IS_SCHEDULED_TEST', value: 'False'; environment name: 'IS_SCHEDULED', value: 'False';
expression { expression {
env.TRIGGER_CD.toBoolean() env.TRIGGER_CD.toBoolean()
} }
@ -197,12 +200,18 @@ pipeline {
} }
steps { steps {
script{ script{
echo "Cron build disabled. New deploy of ${params.TRIGGER_JOB} - ${params.TRIGGER_VERSION} ongoing" echo '\033[31;1;4mNew upstream deploy ongoing\033[0m'
ansiColor("xterm") { echo "Cron build disabled. Component: ${params.TRIGGER_JOB} - ${params.TRIGGER_VERSION}"
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') { ansiColor('xterm') {
checkup("${params.TRIGGER_JOB}", "${params.TRIGGER_VERSION}", "${params.TRIGGER_HOST}"); catchError(buildResult: 'UNSTABLE', stageResult: 'UNSTABLE') {
deploy("${params.TRIGGER_JOB}", "${params.TRIGGER_VERSION}", "${params.TRIGGER_HOST}"); checkup("${params.TRIGGER_JOB}", "${params.TRIGGER_VERSION}", "${params.TRIGGER_HOST}");
} }
if (currentBuild.result == "UNSTABLE") {
return;
}
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
deploy("${params.TRIGGER_JOB}", "${params.TRIGGER_VERSION}", "${params.TRIGGER_HOST}", "${params.TRIGGER_FOO}");
}
} }
} }
@ -214,37 +223,35 @@ 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 {
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");
} }
} }
} }
stage('Deploy manually ') { stage('Deploy manually ') {
when{ when{
allOf{ allOf{
environment name: 'IS_SCHEDULED_TEST', 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 '\033[31;1;4mNew deploy ongoing manually triggered\033[0m'
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"
ansiColor("xterm") { catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') { deploy("${params.TRIGGER_JOB}", "${params.TRIGGER_VERSION}", "${params.TRIGGER_HOST}", "${params.TRIGGER_FOO}");
deploy("${params.TRIGGER_JOB}", "${params.TRIGGER_VERSION}", "${params.TRIGGER_HOST}");
}
} }
} }
} }
} }
@ -260,30 +267,23 @@ pipeline {
echo 'The deploy pipeline worked!' echo 'The deploy pipeline worked!'
emailext attachLog: true,//attachmentsPattern: "**/${ACTION_DEPLOY_FILE}.csv", emailext attachLog: true,//attachmentsPattern: "**/${ACTION_DEPLOY_FILE}.csv",
to: 'roberto.cirillo@isti.cnr.it', to: 'jenkinsbuilds@d4science.org',
subject: "[Jenkins-gCubeDeployer] Deploy report", subject: "[Jenkins-gCubeDeployer] Deploy report",
body: "${currentBuild.fullDisplayName}. Build time: ${currentBuild.durationString}. See ${env.BUILD_URL}. " body: "${currentBuild.fullDisplayName}. Build time: ${currentBuild.durationString}. See ${env.BUILD_URL}. "
} }
failure { failure {
echo 'The deploy pipeline has failed' echo 'The deploy pipeline has failed'
emailext attachLog: true, emailext attachLog: true,
to: 'roberto.cirillo@isti.cnr.it', to: 'jenkinsbuilds@d4science.org',
subject: "[Jenkins-gCubeDeployer] deploy ${currentBuild.fullDisplayName} failed", subject: "[Jenkins-gCubeDeployer] deploy ${currentBuild.fullDisplayName} failed",
body: "Something is wrong with ${env.BUILD_URL}" body: "Something is wrong with ${env.BUILD_URL}"
} }
} }
} }
//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;git pull;./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){
@ -296,17 +296,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("""
@ -317,6 +306,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}");
@ -337,6 +330,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,31 +339,49 @@ def deployJobs(def serviceList){
println("Processing deploy: "+service[ 0 ]) println("Processing deploy: "+service[ 0 ])
catchError(buildResult: 'UNSTABLE', stageResult: 'UNSTABLE') { catchError(buildResult: 'UNSTABLE', stageResult: 'UNSTABLE') {
checkup(service[0], service[ 1 ], service[2]); checkup(service[0], service[ 1 ], service[2]);
deploy(service[0], service[ 1 ], service[2]); }
if (currentBuild.result == "UNSTABLE") {
return;
} }
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
deploy(service[0], service[ 1 ], service[2]);
}
} }
} }
} }
//Deploy only release components. All the component are passed as: componentName,componentVersion
def deployReleaseJobs(def serviceList, String smartgears){ //Run ansible deploy
for (def record : serviceList) { def deploy(String service, String version, String host, String foo){
service=record.split(","); def now = new Date();
stage(service[0]){ println("Going to deploy the service "+service+" with version: "+version+" on target: "+host+" with argument: "+foo);
println("Processing RELEASE deploy: service "+service[ 0 ]+" with version "+service[ 1 ]+" and SG "+smartgears) dir("${ANSIBLE_ROOT_FOLDER}/CD/"){
catchError(buildResult: 'UNSTABLE', stageResult: 'FAILURE') { sh("""
checkupRelease(service[0], service[ 1 ]); git pull;
if (smartgears) """)
deployRelease(service[0], service[ 1 ], smartgears); def statusCode = sh( script: "./deployService.sh $service $version $host $foo;", returnStatus: true);
else sh("""
deployRelease(service[0], service[ 1 ], null); echo " last exit code \$?";
} """)
println("Deploy statusCode value: "+statusCode);
if (statusCode != 0){
currentBuild.result = 'FAILURE'
sh("""
exit $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 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 ->
@ -377,9 +389,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] : null 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" }
} }
@ -388,5 +407,58 @@ 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){
stage("portlets"){
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 "+service+" "+version+" on preproduction ");
dir("${ANSIBLE_ROOT_FOLDER}/CD/"){
sh("""
git pull;
""")
def statusCode = sh( script: "./deployPreprodService.sh $service $version $smartgears ;", returnStatus: true);
sh("""
echo " last exit code \$?";
""")
println("Deploy ended with status: "+statusCode);
if (statusCode != 0){
currentBuild.result = 'FAILURE'
sh("""
exit $statusCode;
""")
}
}
} }

403
README.html Normal file

File diff suppressed because one or more lines are too long

View File

@ -9,20 +9,42 @@ Jenkins Pipeline script to manage one or more gCube components deployment
* [Pipeline: Basic Steps](https://plugins.jenkins.io/workflow-basic-steps) * [Pipeline: Basic Steps](https://plugins.jenkins.io/workflow-basic-steps)
* [Email Extension](https://plugins.jenkins.io/email-ext) (to send emails with attachments) * [Email Extension](https://plugins.jenkins.io/email-ext) (to send emails with attachments)
* Jenkins agent(s) configured with Ansible ver. 2.9.27 or newer * Jenkins agent(s) configured with Ansible ver. 2.9.27 or newer
* One or more Jenkins agents labeled as 'CD' * One or more Jenkins agents labeled as 'ansible'
## Expected usage ## Expected usage
* ContinuousDeployment(CD): configured as post step build on jenkinsjob * ContinuousDeployment(CD): configured as post step build on jenkinsjob
* Scheduled by system: In this case all the pending deployments (CD) will be managed by a temporized trigger * Scheduled by system: In this case all the pending deployments (CD) will be managed by a temporized trigger
* Manually from Jenkins GUI * Manually from Jenkins GUI
## Expected usage ## Expected environment variables
The variables below must be specified as environment variables on the agent where the deployments will be executed:
* IS_SCHEDULED (True | False): if true all the deployment requests will be performed periodically as specified by cron
* ENVIRONMENT: ( DEV | PREPROD | PROD) Indicates the target environment where will be deployed all the artifacts
* DEPLOY_CATEGORY: (Related to release build) one or more Component group (separated by commas) on yaml file where search the components to deploy
* CD: (Continuous Deployment: True | False) if True the remote deploy will be performed
## References ## References
* [Jenkins Pipeline](https://jenkins.io/doc/book/pipeline/) * [Jenkins Pipeline](https://jenkins.io/doc/book/pipeline/)
* [Pipeline Syntax](https://jenkins.io/doc/book/pipeline/syntax/) * [Pipeline Syntax](https://jenkins.io/doc/book/pipeline/syntax/)
## Wiki doc ## Examples
* When configured as post step build on jenkinsjob, there are some variables to pass as triggered parameters. All the values are dinamically set as shown below:
[[images/gCubeDeployer-JenkinsJob.png]]
* The pipeline can run manually. This option is conceived for debug purpose:
[[images/gCubeDeployer-manualRun.png]]
* Follows a stage view example when the pipeline was scheduled by system, but there were any action to do:
[[images/gCubeDeployer-stageview.png]]
## Flow Chart
[[images/FlowChartgCubeDeployer.jpeg]]
## License ## License

Binary file not shown.

After

Width:  |  Height:  |  Size: 98 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 253 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 194 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 403 KiB