Compare commits

...

174 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
Roberto Cirillo ed1071bdb4 Set as variable the yaml group that identify the SG distribution 2022-10-13 11:21:00 +02:00
Roberto Cirillo ba87906dd4 remove println 2022-10-13 10:55:17 +02:00
Roberto Cirillo 628f4c164e renamed var json* to yaml* 2022-10-13 10:53:36 +02:00
Roberto Cirillo 526e7e4a0b optimizing method deployRelease 2022-10-13 10:43:36 +02:00
Roberto Cirillo b0c0011a63 optimize method deployRelease 2022-10-13 10:40:28 +02:00
Roberto Cirillo eb7bf27c81 fix method, add new print 2022-10-13 10:30:24 +02:00
Roberto Cirillo f494d5dbc3 add some print 2022-10-13 10:24:42 +02:00
Roberto Cirillo 6ed0bbb978 replace continue with return 2022-10-12 15:31:47 +02:00
Roberto Cirillo 1a38859d7d add print 2022-10-12 15:25:22 +02:00
Roberto Cirillo b69ed75059 change distro category to Distributions for testing 2022-10-12 15:11:56 +02:00
Roberto Cirillo 25b582538e add new check on smartgears-distribution component name before assign
the version
2022-10-12 15:03:51 +02:00
Roberto Cirillo 8f1fd22867 small fix 2022-10-12 14:47:28 +02:00
Roberto Cirillo 6d756fa30b small fix 2022-10-12 14:31:17 +02:00
Roberto Cirillo e9df1da14b small fix 2022-10-12 14:30:08 +02:00
Roberto Cirillo d8d13be529 add new print 2022-10-12 14:26:47 +02:00
Roberto Cirillo c1aeb43300 try to add the smartgears version to the var 2022-10-12 14:18:50 +02:00
Roberto Cirillo 3c6da95e7a add check on release job on manual stage 2022-10-12 11:40:55 +02:00
Roberto Cirillo ab2eb45cbd fix call to deployRelease 2022-10-12 11:33:43 +02:00
Roberto Cirillo 3813bda08d small fix 2022-10-12 11:24:18 +02:00
Roberto Cirillo 807ae18099 small fix 2022-10-12 11:20:36 +02:00
Roberto Cirillo 517f5cde05 small fix 2022-10-12 11:14:12 +02:00
Roberto Cirillo 6b9ab6a413 SmartGears var as string 2022-10-12 11:07:55 +02:00
Roberto Cirillo e739de9ec3 add explicit check on distribution category 2022-10-12 11:03:28 +02:00
Roberto Cirillo f3f51d1e93 fix variable 2022-10-12 10:50:04 +02:00
Roberto Cirillo 70c41d75a0 removed wrong line 2022-10-12 10:49:04 +02:00
Roberto Cirillo 71d9b17425 enable check on special yaml category distribution. restored
IS_SCHEDULED_TEST var
2022-10-12 10:46:02 +02:00
Roberto Cirillo de1e8cfd01 try to set more than one yaml section on env var DEPLOY_CATEGORY 2022-10-12 10:20:56 +02:00
Roberto Cirillo fcfd5804dd update comment 2022-10-11 15:08:29 +02:00
Roberto Cirillo efd8338e7d Merge branch 'master' of https://code-repo.d4science.org/gCubeCI/gCubeDeployer 2022-10-11 15:06:54 +02:00
Roberto Cirillo e0750810fd Restore IS_SCHEDULED var before the merge 2022-10-11 15:04:29 +02:00
Roberto Cirillo a2ba4ba21a add userIdCause to pending deploy. In this way it will add the job to
the pending deployments when the deploy is scheduled
2022-10-11 14:43:20 +02:00
Roberto Cirillo 583879e393 remove unused method 2022-10-11 11:59:50 +02:00
Roberto Cirillo 05ef4fce32 replace name with userID 2022-10-11 11:47:04 +02:00
Roberto Cirillo 33e98eadbc remove Cirillo user check 2022-10-11 11:45:18 +02:00
Roberto Cirillo c941a44f52 fix syntax 2022-10-11 11:44:29 +02:00
Roberto Cirillo 010b1c950b release stage: add Cirillo user check 2022-10-11 11:38:01 +02:00
Roberto Cirillo 928bbfa138 replace gCubeBuilder string with RELEASE_JOB var 2022-10-11 10:47:22 +02:00
Roberto Cirillo c9dee5146a add when clause to pending deploy stage 2022-10-11 10:27:40 +02:00
Roberto Cirillo af670ec274 add git pull before the deploy script 2022-10-11 10:21:31 +02:00
Roberto Cirillo d4fff4a12d fix syntax 2022-10-11 10:17:42 +02:00
Roberto Cirillo 6f9a92a330 add separated methods dedicated to the release deployment 2022-10-11 10:09:24 +02:00
Roberto Cirillo 3a1daa7401 small fix 2022-10-11 09:58:14 +02:00
Roberto Cirillo cbbbf67681 add new print 2022-10-11 09:44:27 +02:00
Roberto Cirillo b645919668 small fix 2022-10-11 09:41:02 +02:00
Roberto Cirillo f55bc0881c small fix 2022-10-11 09:28:05 +02:00
Roberto Cirillo 3b169c4596 small fix 2022-10-11 09:20:04 +02:00
Roberto Cirillo fa12ee4e08 small fix 2022-10-11 09:03:00 +02:00
Roberto Cirillo d9a86cc855 small fix 2022-10-11 08:59:34 +02:00
Roberto Cirillo b135184761 small fix 2022-10-11 08:51:29 +02:00
Roberto Cirillo e7a91134e4 add print 2022-10-10 17:35:58 +02:00
Roberto Cirillo f3b5b8535d fix checkupRelease method 2022-10-10 17:33:35 +02:00
Roberto Cirillo c6ac2ca316 fix collection fields 2022-10-10 17:30:28 +02:00
Roberto Cirillo 9c6e18204f moving jsonConfig decalration outside the if 2022-10-10 17:18:24 +02:00
Roberto Cirillo 74df921160 small fix 2022-10-10 17:15:12 +02:00
Roberto Cirillo dc26e7af97 small fix 2022-10-10 17:13:16 +02:00
Roberto Cirillo 244797a151 add condition in order to avoid job stages when the job is gCubeBuilder
pipeline
2022-10-10 17:10:42 +02:00
Roberto Cirillo 65971dff31 remove assert check on release version 2022-10-10 15:16:24 +02:00
Roberto Cirillo 41962f0541 set verbose default to true 2022-10-10 15:13:00 +02:00
Roberto Cirillo 3683c06a26 add import of org.yaml.snakeyaml.Yaml 2022-10-10 15:08:33 +02:00
Roberto Cirillo 0667282ccd add deploy from release stage 2022-10-10 15:05:37 +02:00
Roberto Cirillo bcff06a388 add RELEASE_URL input parameter 2022-10-10 14:47:21 +02:00
Roberto Cirillo 43a402ab16 variables refactoring; add new methods related to the release deployment
tasks;
2022-10-10 13:31:52 +02:00
Roberto Cirillo d1a687f021 fix parse method 2022-10-06 14:55:26 +02:00
Roberto Cirillo f7262e098b removed wrong print 2022-10-06 14:49:31 +02:00
Roberto Cirillo 89fe9dda2d fix syntax 2022-10-06 14:45:12 +02:00
Roberto Cirillo 62142b5c59 fix parse method 2022-10-06 14:32:33 +02:00
Roberto Cirillo 862fa2e8b0 change method involed 2022-10-06 14:25:22 +02:00
Roberto Cirillo a0b0d90408 fix syntax 2022-10-06 14:16:22 +02:00
Roberto Cirillo 8670b1f15b renamed in IS_SCHEDULED_TEST 2022-10-06 14:07:08 +02:00
Roberto Cirillo dd47ab701d fix equals 2022-10-06 13:58:37 +02:00
Roberto Cirillo 47725a421f fix equals condition 2022-10-06 13:54:44 +02:00
Roberto Cirillo 4d16e4d272 fix syntax 2022-10-06 13:37:18 +02:00
Roberto Cirillo c0ce9ddef3 fix syntax 2022-10-06 13:32:48 +02:00
Roberto Cirillo 4c3029cb0b fix sintax 2022-10-06 12:51:12 +02:00
Roberto Cirillo cf61dba571 fix if 2022-10-06 12:49:33 +02:00
Roberto Cirillo 1e3270999f add conditional the report url discovering step 2022-10-06 12:47:18 +02:00
Roberto Cirillo 2577fa7ac8 add params. to var report_number 2022-10-06 12:37:47 +02:00
Roberto Cirillo 5b34d2b1a8 add env variables for new input params 2022-10-06 11:59:44 +02:00
Roberto Cirillo ddfa536c69 add load build report's content. add input parameters related to the
build report
2022-10-06 09:58:03 +02:00
Roberto Cirillo 48aa2cabce Update 'README.md'
update readme
2022-10-05 11:12:20 +02:00
Roberto Cirillo 47aa7111e2 fix conflicts
Merge branch 'feature/23745'
2022-10-05 10:31:10 +02:00
Roberto Cirillo aeb7c55861 removed IS_CRON_TMP var. Restored the old one IS_CRON 2022-10-04 16:26:49 +02:00
Roberto Cirillo 9a7fd3687e removed unused imports 2022-10-04 16:24:43 +02:00
Roberto Cirillo 15b62f11b0 Merge branch 'feature/23745' 2022-10-04 16:21:46 +02:00
Roberto Cirillo fda6187b4c restored checkup and deploy methods in the same catch 2022-09-08 12:22:39 +02:00
Roberto Cirillo e075a3d92b set agent label to ansible 2022-09-08 12:07:26 +02:00
Roberto Cirillo cc890e4b8b set build to SUCCESS and stage to FAILURE if the version doesn't contain
SNAPSHOT, in deploy from upstream case; remove SNAPSHOT check on deploy
manually stage
2022-09-08 10:28:09 +02:00
7 changed files with 704 additions and 77 deletions

346
Jenkinsfile vendored
View File

@ -1,12 +1,9 @@
#!groovy
import groovy.io.FileType
import static groovy.io.FileType.FILES
import jenkins.model.*
import hudson.FilePath;
import jenkins.model.Jenkins;
import org.yaml.snakeyaml.Yaml
import groovy.json.JsonSlurper
/**
* Deploy components to the D4Science Infrastructure (dev-only)
* Deploy gCube components on D4Science Infrastructure (dev and preprod environments)
*
* Roberto Cirillo (ISTI-CNR)
*/
@ -14,13 +11,33 @@ import jenkins.model.Jenkins;
// related jenkins job: https://jenkins.d4science.org/job/gCubeDeployer/
def agent_root_folder = '/var/lib/jenkins'
def verbose = true
def yamlConfig
def text
if ("${params.gCube_release_version}" || "${params.RELEASE_URL}"){
String releaseURL='';
if ("${params.gCube_release_version}"){
//locate the release file
releaseURL = "https://code-repo.d4science.org/gCubeCI/gCubeReleases/raw/branch/master/open/gcube-${gCube_release_version}.yaml"
}else{
releaseURL = "${params.RELEASE_URL}"
}
//load the release file
text = releaseURL.toURL().getText()
//parsing
yamlConfig = new Yaml().load(text)
if (verbose)
println yamlConfig.inspect()
echo "Building gCube v. ${yamlConfig.gCube_release.Version}"
if (verbose) {
echo "Found components:"
yamlConfig.gCube_release.Components.each { println it.key }
}
}
def deployList
def backupList
if (params.deployFile) {
println "Using custom deploy file"
deployList = params.deployFile
}
pipeline {
agent {
@ -39,16 +56,37 @@ pipeline {
environment {
AGENT_ROOT_FOLDER = "${agent_root_folder}"
// folder where all the pending deployment will be added
PENDING_DEPLOY_FOLDER="${agent_root_folder}/CD/"
CD_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}"
// deploy file related to the current pipeline job
DEPLOY_FILE = "${PENDING_DEPLOY_FOLDER}deploy.${PIPELINE_BUILD_NUMBER}.csv"
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= "${WORKSPACE}/CD-${PIPELINE_BUILD_NUMBER}"
// artifacts coordinates
TRIGGER_JOB= "${params.TRIGGER_JOB}"
TRIGGER_VERSION= "${params.TRIGGER_VERSION}"
TRIGGER_HOST="${params.TRIGGER_HOST}"
// enable the ContinuousDeployment if TRUE
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
GCUBE_RELEASE_NUMBER = "${params.gCube_release_version}"
//Category name of the components candidates to the remote deployment
DEPLOY_CATEGORY="${env.DEPLOY_CATEGORY}"
//Job name of the release pipeline
RELEASE_JOB='Pipeline-gCubeBuilder'
//URL to the YAML file. Used alternatively to RELEASE_JOB
RELEASE_URL= "${params.RELEASE_URL}"
// username of ReleaseManager. Used for limiting the preproduction deployments
RELEASE_MANAGER_USER='giancarlo.panichi'
// 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 {
@ -64,10 +102,15 @@ pipeline {
booleanParam(name: 'TRIGGER_CD',
defaultValue: true,
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',
defaultValue: '',
description: 'Leave blank if executed outside gCube release')
description: 'The number of the current gCube release. Leave blank if executed outside gCube release.')
string(name: 'RELEASE_URL',
defaultValue: '',
description: 'URL to the yaml file. Leave blank if executed outside gCube release.')
}
stages {
@ -83,34 +126,34 @@ pipeline {
}
stage('Deploy from system') {
when{
allOf{
triggeredBy 'TimerTrigger'
// maybe we can add a new condition in order to consider the manual execution of this pipeline
environment name: 'IS_SCHEDULED', value: 'True'
}
anyOf{
allOf{
triggeredBy 'TimerTrigger'
environment name: 'IS_SCHEDULED', value: 'True'
}
}
}
steps {
echo 'Cron build enabled. Deploy from system ongoing'
echo 'Cron build enabled. \033[31;1;4mDeploy from system ongoing\033[0m'
script {
echo "pipeline was triggered by ${params.TRIGGER_JOB}"
println("Going to deploy all the pending deployments")
def deployFolder="CD-${env.BUILD_NUMBER}";
deployPendingJobs(deployFolder);
parseDeployPendingJobs(deployFolder);
}
}
}
stage('Nothing to do ') {
when{
anyOf{
allOf{
triggeredBy 'TimerTrigger'
environment name: 'IS_SCHEDULED', value: 'False'
}
allOf{
triggeredBy 'TimerTrigger'
environment name: 'IS_SCHEDULED', value: 'False'
}
}
steps {
echo 'Do Nothing: cron build disabled'
echo '\033[31;1;4mGoing to sleep\033[0m'
sh ' exit 0; '
}
}
stage('New pending deploy ') {
@ -121,18 +164,21 @@ pipeline {
triggeredBy 'UpstreamCause'
triggeredBy 'UserIdCause'
}
expression { params.TRIGGER_JOB != "${RELEASE_JOB}" }
}
steps {
sh '''
echo "Cron build enabled. New deploy of ${TRIGGER_JOB} - ${TRIGGER_VERSION} will be added to the 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;
if grep -q \"\${TRIGGER_JOB}\" \${DEPLOY_FILE}; then
echo "component ${TRIGGER_JOB} already added. Nothing to add."
else
echo "${TRIGGER_JOB},${TRIGGER_VERSION},${TRIGGER_HOST}" >> ${DEPLOY_FILE}
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
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.
// Not sure this is the best approach
catchError(buildResult: 'UNSTABLE', stageResult: 'UNSTABLE') {
sh("""
exit 126;
@ -150,34 +196,62 @@ pipeline {
triggeredBy 'BuildUpstreamCause'
triggeredBy 'UpstreamCause'
}
expression { params.TRIGGER_JOB != "${RELEASE_JOB}" }
}
steps {
echo "Cron build disabled. New deploy of ${params.TRIGGER_JOB} - ${params.TRIGGER_VERSION} ongoing"
ansiColor("xterm") {
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
checkup("${params.TRIGGER_JOB}", "${params.TRIGGER_VERSION}", "${params.TRIGGER_HOST}");
deploy("${params.TRIGGER_JOB}", "${params.TRIGGER_VERSION}", "${params.TRIGGER_HOST}");
}
}
script{
echo '\033[31;1;4mNew upstream deploy ongoing\033[0m'
echo "Cron build disabled. Component: ${params.TRIGGER_JOB} - ${params.TRIGGER_VERSION}"
ansiColor('xterm') {
catchError(buildResult: 'UNSTABLE', stageResult: 'UNSTABLE') {
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}");
}
}
}
}
}
stage('Deploy from gCubeRelease ') {
when{
anyOf{
triggeredBy 'BuildUpstreamCause'
triggeredBy 'UpstreamCause'
// added just for testing . To Remove.
triggeredBy cause: "UserIdCause", detail: "${RELEASE_MANAGER_USER}"
}
// we should improve this conditional check
equals(actual: "${params.TRIGGER_JOB}", expected: "${RELEASE_JOB}")
}
steps {
script{
if("${DEPLOY_CATEGORY}"){
echo '\033[31;1;4mGoing to deploy gCube Release \033[0m'
deployRelease("${DEPLOY_CATEGORY}", yamlConfig);
}else println ("CATEGORIES NOT FOUND. ENVIRONMENT NOT SET FOR RELEASE DEPLOYMENT. NOTHING TO DO");
}
}
}
stage('Deploy manually ') {
when{
allOf{
environment name: 'IS_SCHEDULED', value: 'False';
triggeredBy 'UserIdCause'
}
expression { params.TRIGGER_JOB != "${RELEASE_JOB}" }
}
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"
ansiColor("xterm") {
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
checkup("${params.TRIGGER_JOB}", "${params.TRIGGER_VERSION}", "${params.TRIGGER_HOST}");
deploy("${params.TRIGGER_JOB}", "${params.TRIGGER_VERSION}", "${params.TRIGGER_HOST}");
}
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
deploy("${params.TRIGGER_JOB}", "${params.TRIGGER_VERSION}", "${params.TRIGGER_HOST}", "${params.TRIGGER_FOO}");
}
}
}
}
@ -187,21 +261,20 @@ pipeline {
sh '''
echo 'Sending report'
'''
//cat ./${ACTION_DEPLOY_FILE}.csv
}
}
success {
echo 'The deploy pipeline worked!'
emailext attachLog: true,//attachmentsPattern: "**/${ACTION_DEPLOY_FILE}.csv",
to: 'roberto.cirillo@isti.cnr.it',
to: 'jenkinsbuilds@d4science.org',
subject: "[Jenkins-gCubeDeployer] Deploy report",
body: "${currentBuild.fullDisplayName}. Build time: ${currentBuild.durationString}. See ${env.BUILD_URL}. "
}
failure {
echo 'The deploy pipeline has failed'
emailext attachLog: true,
to: 'roberto.cirillo@isti.cnr.it',
to: 'jenkinsbuilds@d4science.org',
subject: "[Jenkins-gCubeDeployer] deploy ${currentBuild.fullDisplayName} failed",
body: "Something is wrong with ${env.BUILD_URL}"
}
@ -209,16 +282,8 @@ 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 $CD_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){
@ -231,9 +296,22 @@ def checkup(String service, String version, String host){
""")
}
//Implement a new method in order to check the input parameters
def checkupRelease(String service, String version){
sh("""
case "$version" in
**SNAPSHOT) echo "version contains SNAPSHOT. EXIT because this is a release build" ; exit 1;;
**latest) echo "version contains latest" ;;
* ) echo "version without SNAPSHOT. Go ahead";;
esac
""")
}
/* DEPLOY METHODS*/
//parse all csv files found in the local folder and deploy the components defined inside
def deployPendingJobs( def deployFolder){
def parseDeployPendingJobs( def deployFolder){
println ("searching files in folder ${deployFolder}");
def files = findFiles(glob: "${deployFolder}/*.csv")
if (files == null){
@ -244,23 +322,143 @@ def deployPendingJobs( def deployFolder){
def records = readCSV file: "${file.path}"
for (def record : records) {
println("Processing record: "+record)
if(!serviceList.contains(record.get(0))){
stage(record.get(0)){
println "Deploy on going of component: ${record.get(0)}"
catchError(buildResult: 'UNSTABLE', stageResult: 'UNSTABLE') {
checkup(record.get(0), record.get(1), record.get(2));
deploy(record.get(0), record.get(1), record.get(2));
}
}
serviceList << record.get(0)
}else{
echo "${record.get(0)} already deployed. Deployment skipped."
}
}
serviceList += "${record.get(0)},${record.get(1)},${record.get(2)}";
}
sh "rm ${file.path}"
}
sh "rm -Rf ${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) {
service=record.split(",");
stage(service[0]){
println("Processing deploy: "+service[ 0 ])
catchError(buildResult: 'UNSTABLE', stageResult: 'UNSTABLE') {
checkup(service[0], service[ 1 ], service[2]);
}
if (currentBuild.result == "UNSTABLE") {
return;
}
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
deploy(service[0], service[ 1 ], service[2]);
}
}
}
}
//Run ansible deploy
def deploy(String service, String version, String host, String foo){
def now = new Date();
println("Going to deploy the service "+service+" with version: "+version+" on target: "+host+" with argument: "+foo);
dir("${ANSIBLE_ROOT_FOLDER}/CD/"){
sh("""
git pull;
""")
def statusCode = sh( script: "./deployService.sh $service $version $host $foo;", returnStatus: true);
sh("""
echo " last exit code \$?";
""")
println("Deploy statusCode value: "+statusCode);
if (statusCode != 0){
currentBuild.result = 'FAILURE'
sh("""
exit $statusCode;
""")
}
}
}
/* 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 ->
if (categories.contains(group_name)){
for ( def category : categories){
if("${group_name}" == "$category"){
if (category == "${DISTRIBUTION_CATEGORY}"){
//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" }
}
return;
}
}
}
}
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,16 +9,42 @@ Jenkins Pipeline script to manage one or more gCube components deployment
* [Pipeline: Basic Steps](https://plugins.jenkins.io/workflow-basic-steps)
* [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
* One or more Jenkins agents labeled as 'CD'
* One or more Jenkins agents labeled as 'ansible'
## Expected parameters
## Expected usage
* 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
* Manually from Jenkins GUI
## 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
* [Jenkins Pipeline](https://jenkins.io/doc/book/pipeline/)
* [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

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