generated from gCubeCI/Pipeline-Docker-Template
Compare commits
174 Commits
feature/23
...
master
Author | SHA1 | Date |
---|---|---|
Roberto Cirillo | 5e84d57f91 | |
Roberto Cirillo | 545ec46752 | |
Roberto Cirillo | 6a162840a4 | |
Roberto Cirillo | 4a89d6b448 | |
Roberto Cirillo | d678d87ec8 | |
Roberto Cirillo | 78904c0793 | |
Roberto Cirillo | fea4741152 | |
Roberto Cirillo | c9af197c68 | |
Roberto Cirillo | 4ab3535e90 | |
Roberto Cirillo | ad9f9382fb | |
Roberto Cirillo | 5bbf75f4fd | |
Roberto Cirillo | 8ae9a74ff0 | |
Roberto Cirillo | cf0ea75460 | |
Roberto Cirillo | 4728bd16b9 | |
Roberto Cirillo | ecc8b71cbe | |
Roberto Cirillo | ceaa196895 | |
Roberto Cirillo | ec7ae82e9b | |
Roberto Cirillo | d56d1a693e | |
Roberto Cirillo | dbee8ad96c | |
Roberto Cirillo | 39e1daf6c7 | |
Roberto Cirillo | 693c528411 | |
Roberto Cirillo | 8a95929a8a | |
Roberto Cirillo | c6832781d6 | |
Roberto Cirillo | 38f36774aa | |
Roberto Cirillo | 951d53cef2 | |
Roberto Cirillo | 4adce129eb | |
Roberto Cirillo | 7583e98a94 | |
Roberto Cirillo | 3e4029c597 | |
Roberto Cirillo | 8ae88c9d04 | |
Roberto Cirillo | 974a264b32 | |
Roberto Cirillo | f823ac8d19 | |
Roberto Cirillo | 0ec2f9b56d | |
Roberto Cirillo | 30f75a203e | |
Roberto Cirillo | 87931065a3 | |
Roberto Cirillo | 2fbc25b0fd | |
Roberto Cirillo | a52265bcdd | |
Roberto Cirillo | dd691f73c9 | |
Roberto Cirillo | 48e2c3fd47 | |
Roberto Cirillo | ba88a51028 | |
Roberto Cirillo | 1609eb2c1e | |
Roberto Cirillo | 1a63a95de4 | |
Roberto Cirillo | d55c3c728f | |
Roberto Cirillo | 77cf75579c | |
Roberto Cirillo | 203967e625 | |
Roberto Cirillo | f9c0476638 | |
Roberto Cirillo | 14dcf64e6d | |
Roberto Cirillo | 12be87c118 | |
Roberto Cirillo | 6ada59467f | |
Roberto Cirillo | 8e4a4ea249 | |
Roberto Cirillo | ce2beba794 | |
Roberto Cirillo | 9d7fbced7f | |
Roberto Cirillo | b86ed090b9 | |
Roberto Cirillo | b0e4dd25be | |
Roberto Cirillo | eacc8c2d97 | |
Roberto Cirillo | b26d4cde46 | |
Roberto Cirillo | 65d5636324 | |
Roberto Cirillo | 045849a57b | |
Roberto Cirillo | 7f786fbbe7 | |
Roberto Cirillo | 195ad81f65 | |
Roberto Cirillo | 942176c290 | |
Roberto Cirillo | 6a8a52bbd3 | |
Roberto Cirillo | 5b236a4f63 | |
Roberto Cirillo | 6f847cecf7 | |
Roberto Cirillo | c6cccec47d | |
Roberto Cirillo | e70250bfdd | |
Roberto Cirillo | 8c37113fcb | |
Roberto Cirillo | d2ccba5770 | |
Roberto Cirillo | 5f9f635a61 | |
Roberto Cirillo | 3f2fb836c0 | |
Roberto Cirillo | 2606032208 | |
Roberto Cirillo | 2d35aba7d5 | |
Roberto Cirillo | 8333695959 | |
Roberto Cirillo | 8076da5291 | |
Roberto Cirillo | 59c1d9741a | |
Roberto Cirillo | 0c3d39c63d | |
Roberto Cirillo | f48df8bc6a | |
Roberto Cirillo | eb8b09115b | |
Roberto Cirillo | c0cecd9790 | |
Roberto Cirillo | 6974b8ee91 | |
Roberto Cirillo | 2c859c8db7 | |
Roberto Cirillo | 0d3a7ae517 | |
Roberto Cirillo | 6e4225dc3f | |
Roberto Cirillo | 9f7aa7cd4e | |
Roberto Cirillo | f76b12e52e | |
Roberto Cirillo | 9527de940c | |
Roberto Cirillo | e1b08e8cc3 | |
Roberto Cirillo | 599ab1ebf7 | |
Roberto Cirillo | ed1071bdb4 | |
Roberto Cirillo | ba87906dd4 | |
Roberto Cirillo | 628f4c164e | |
Roberto Cirillo | 526e7e4a0b | |
Roberto Cirillo | b0c0011a63 | |
Roberto Cirillo | eb7bf27c81 | |
Roberto Cirillo | f494d5dbc3 | |
Roberto Cirillo | 6ed0bbb978 | |
Roberto Cirillo | 1a38859d7d | |
Roberto Cirillo | b69ed75059 | |
Roberto Cirillo | 25b582538e | |
Roberto Cirillo | 8f1fd22867 | |
Roberto Cirillo | 6d756fa30b | |
Roberto Cirillo | e9df1da14b | |
Roberto Cirillo | d8d13be529 | |
Roberto Cirillo | c1aeb43300 | |
Roberto Cirillo | 3c6da95e7a | |
Roberto Cirillo | ab2eb45cbd | |
Roberto Cirillo | 3813bda08d | |
Roberto Cirillo | 807ae18099 | |
Roberto Cirillo | 517f5cde05 | |
Roberto Cirillo | 6b9ab6a413 | |
Roberto Cirillo | e739de9ec3 | |
Roberto Cirillo | f3f51d1e93 | |
Roberto Cirillo | 70c41d75a0 | |
Roberto Cirillo | 71d9b17425 | |
Roberto Cirillo | de1e8cfd01 | |
Roberto Cirillo | fcfd5804dd | |
Roberto Cirillo | efd8338e7d | |
Roberto Cirillo | e0750810fd | |
Roberto Cirillo | a2ba4ba21a | |
Roberto Cirillo | 583879e393 | |
Roberto Cirillo | 05ef4fce32 | |
Roberto Cirillo | 33e98eadbc | |
Roberto Cirillo | c941a44f52 | |
Roberto Cirillo | 010b1c950b | |
Roberto Cirillo | 928bbfa138 | |
Roberto Cirillo | c9dee5146a | |
Roberto Cirillo | af670ec274 | |
Roberto Cirillo | d4fff4a12d | |
Roberto Cirillo | 6f9a92a330 | |
Roberto Cirillo | 3a1daa7401 | |
Roberto Cirillo | cbbbf67681 | |
Roberto Cirillo | b645919668 | |
Roberto Cirillo | f55bc0881c | |
Roberto Cirillo | 3b169c4596 | |
Roberto Cirillo | fa12ee4e08 | |
Roberto Cirillo | d9a86cc855 | |
Roberto Cirillo | b135184761 | |
Roberto Cirillo | e7a91134e4 | |
Roberto Cirillo | f3b5b8535d | |
Roberto Cirillo | c6ac2ca316 | |
Roberto Cirillo | 9c6e18204f | |
Roberto Cirillo | 74df921160 | |
Roberto Cirillo | dc26e7af97 | |
Roberto Cirillo | 244797a151 | |
Roberto Cirillo | 65971dff31 | |
Roberto Cirillo | 41962f0541 | |
Roberto Cirillo | 3683c06a26 | |
Roberto Cirillo | 0667282ccd | |
Roberto Cirillo | bcff06a388 | |
Roberto Cirillo | 43a402ab16 | |
Roberto Cirillo | d1a687f021 | |
Roberto Cirillo | f7262e098b | |
Roberto Cirillo | 89fe9dda2d | |
Roberto Cirillo | 62142b5c59 | |
Roberto Cirillo | 862fa2e8b0 | |
Roberto Cirillo | a0b0d90408 | |
Roberto Cirillo | 8670b1f15b | |
Roberto Cirillo | dd47ab701d | |
Roberto Cirillo | 47725a421f | |
Roberto Cirillo | 4d16e4d272 | |
Roberto Cirillo | c0ce9ddef3 | |
Roberto Cirillo | 4c3029cb0b | |
Roberto Cirillo | cf61dba571 | |
Roberto Cirillo | 1e3270999f | |
Roberto Cirillo | 2577fa7ac8 | |
Roberto Cirillo | 5b34d2b1a8 | |
Roberto Cirillo | ddfa536c69 | |
Roberto Cirillo | 48aa2cabce | |
Roberto Cirillo | 47aa7111e2 | |
Roberto Cirillo | aeb7c55861 | |
Roberto Cirillo | 9a7fd3687e | |
Roberto Cirillo | 15b62f11b0 | |
Roberto Cirillo | fda6187b4c | |
Roberto Cirillo | e075a3d92b | |
Roberto Cirillo | cc890e4b8b |
|
@ -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;
|
||||
""")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
File diff suppressed because one or more lines are too long
32
README.md
32
README.md
|
@ -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 |
Loading…
Reference in New Issue