generated from gCubeCI/Pipeline-Docker-Template
Compare commits
No commits in common. "master" and "testColor" have entirely different histories.
|
@ -1,9 +1,8 @@
|
|||
#!groovy
|
||||
import org.yaml.snakeyaml.Yaml
|
||||
import groovy.json.JsonSlurper
|
||||
|
||||
/**
|
||||
* Deploy gCube components on D4Science Infrastructure (dev and preprod environments)
|
||||
* Deploy gCube components on D4Science Infrastructure (dev-only)
|
||||
*
|
||||
* Roberto Cirillo (ISTI-CNR)
|
||||
*/
|
||||
|
@ -58,7 +57,7 @@ pipeline {
|
|||
AGENT_ROOT_FOLDER = "${agent_root_folder}"
|
||||
// folder where all the pending deployment will be added
|
||||
PENDING_DEPLOY_FOLDER="${agent_root_folder}/CD/"
|
||||
ANSIBLE_ROOT_FOLDER = "${agent_root_folder}/ansible-repos/ansible-playbooks/d4science-smartgears-services"
|
||||
ANSIBLE_ROOT_FOLDER = "${agent_root_folder}/ansible-repos/ansible-playbooks/d4science-ghn-cluster/CD"
|
||||
PIPELINE_BUILD_NUMBER = "${env.BUILD_NUMBER}"
|
||||
// deploy file related to the current pipeline job
|
||||
DEPLOY_FILE = "${PENDING_DEPLOY_FOLDER}deploy.${PIPELINE_BUILD_NUMBER}.csv"
|
||||
|
@ -71,8 +70,6 @@ pipeline {
|
|||
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
|
||||
|
@ -82,11 +79,9 @@ pipeline {
|
|||
//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'
|
||||
RELEASE_MANAGER_USER='roberto.cirillo'
|
||||
// name of Smartgears distribution group, defined in the yaml file ( only for release deployments)
|
||||
DISTRIBUTION_CATEGORY='Distribution'
|
||||
// name of Portlets group, defined in the yaml file ( only for release deployments)
|
||||
PORTLET_CATEGORY='Portlets'
|
||||
}
|
||||
|
||||
parameters {
|
||||
|
@ -102,9 +97,6 @@ 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: 'The number of the current gCube release. Leave blank if executed outside gCube release.')
|
||||
|
@ -168,7 +160,7 @@ pipeline {
|
|||
}
|
||||
steps {
|
||||
sh '''
|
||||
echo '\033[31;1;4mNew pending deploy/033[0m'
|
||||
echo '\033[31;1;4mNew pending deploy added to the queue/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
|
||||
|
@ -203,15 +195,10 @@ pipeline {
|
|||
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}");
|
||||
}
|
||||
catchError(buildResult: 'UNSTABLE', stageResult: 'FAILURE') {
|
||||
checkup("${params.TRIGGER_JOB}", "${params.TRIGGER_VERSION}", "${params.TRIGGER_HOST}");
|
||||
deploy("${params.TRIGGER_JOB}", "${params.TRIGGER_VERSION}", "${params.TRIGGER_HOST}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -223,18 +210,18 @@ pipeline {
|
|||
anyOf{
|
||||
triggeredBy 'BuildUpstreamCause'
|
||||
triggeredBy 'UpstreamCause'
|
||||
// added just for testing . To Remove.
|
||||
//added just for testing . To Remove.
|
||||
triggeredBy cause: "UserIdCause", detail: "${RELEASE_MANAGER_USER}"
|
||||
}
|
||||
// we should improve this conditional check
|
||||
// we should improve this conditional check
|
||||
equals(actual: "${params.TRIGGER_JOB}", expected: "${RELEASE_JOB}")
|
||||
}
|
||||
steps {
|
||||
script{
|
||||
if("${DEPLOY_CATEGORY}"){
|
||||
echo '\033[31;1;4mGoing to deploy gCube Release \033[0m'
|
||||
println("Going to deploy the Release components")
|
||||
deployRelease("${DEPLOY_CATEGORY}", yamlConfig);
|
||||
}else println ("CATEGORIES NOT FOUND. ENVIRONMENT NOT SET FOR RELEASE DEPLOYMENT. NOTHING TO DO");
|
||||
}else { println ("CATEGORIES NOT FOUND ON YAML FILE. SKIP TO NEXT STAGE");}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -250,7 +237,7 @@ pipeline {
|
|||
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"
|
||||
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}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -267,23 +254,30 @@ pipeline {
|
|||
echo 'The deploy pipeline worked!'
|
||||
|
||||
emailext attachLog: true,//attachmentsPattern: "**/${ACTION_DEPLOY_FILE}.csv",
|
||||
to: 'jenkinsbuilds@d4science.org',
|
||||
to: 'roberto.cirillo@isti.cnr.it',
|
||||
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: 'jenkinsbuilds@d4science.org',
|
||||
to: 'roberto.cirillo@isti.cnr.it',
|
||||
subject: "[Jenkins-gCubeDeployer] deploy ${currentBuild.fullDisplayName} failed",
|
||||
body: "Something is wrong with ${env.BUILD_URL}"
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* CHECKUP METHODS */
|
||||
//launch ansible deploy
|
||||
def deploy(String service, String version, String host){
|
||||
def now = new Date();
|
||||
println("Going to deploy the service "+service+" with version: "+version+" on target: "+host);
|
||||
def statusCode = sh( script: "cd $ANSIBLE_ROOT_FOLDER;./deployService.sh $service $version $host;", returnStdout: true);
|
||||
sh("""
|
||||
echo " last exit code \$?";
|
||||
""")
|
||||
println("Deploy ended with status: "+statusCode);
|
||||
}
|
||||
|
||||
//Implement a new method in order to check the input parameters
|
||||
def checkup(String service, String version, String host){
|
||||
|
@ -296,6 +290,17 @@ def checkup(String service, String version, String host){
|
|||
""")
|
||||
}
|
||||
|
||||
//launch ansible deploy
|
||||
def deployRelease(String service, String version, String smartgears){
|
||||
def now = new Date();
|
||||
println("Going to deploy the service "+service+" with version: "+version+" on preproduction ");
|
||||
def statusCode = sh( script: "cd $ANSIBLE_ROOT_FOLDER;git pull;./deployPreprodService.sh $service $version $smartgears ;", returnStdout: true);
|
||||
sh("""
|
||||
echo " last exit code \$?";
|
||||
""")
|
||||
println("Deploy ended with status: "+statusCode);
|
||||
}
|
||||
|
||||
//Implement a new method in order to check the input parameters
|
||||
def checkupRelease(String service, String version){
|
||||
sh("""
|
||||
|
@ -306,10 +311,6 @@ def checkupRelease(String service, String version){
|
|||
esac
|
||||
""")
|
||||
}
|
||||
|
||||
|
||||
/* DEPLOY METHODS*/
|
||||
|
||||
//parse all csv files found in the local folder and deploy the components defined inside
|
||||
def parseDeployPendingJobs( def deployFolder){
|
||||
println ("searching files in folder ${deployFolder}");
|
||||
|
@ -330,7 +331,6 @@ def parseDeployPendingJobs( def deployFolder){
|
|||
deployJobs(serviceList.unique())
|
||||
}
|
||||
}
|
||||
|
||||
//Deploy jobs from an input list with the following elements: serviceName,serviceVersion,targetHost. Create a new stage for any job
|
||||
def deployJobs(def serviceList){
|
||||
for (def record : serviceList) {
|
||||
|
@ -339,49 +339,31 @@ def deployJobs(def serviceList){
|
|||
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 only release components. All the component are passed as: componentName,componentVersion
|
||||
def deployReleaseJobs(def serviceList, String smartgears){
|
||||
for (def record : serviceList) {
|
||||
service=record.split(",");
|
||||
stage(service[0]){
|
||||
println("Processing RELEASE deploy: service "+service[ 0 ]+" with version "+service[ 1 ]+" and SG "+smartgears)
|
||||
catchError(buildResult: 'UNSTABLE', stageResult: 'FAILURE') {
|
||||
checkupRelease(service[0], service[ 1 ]);
|
||||
if (smartgears)
|
||||
deployRelease(service[0], service[ 1 ], smartgears);
|
||||
else
|
||||
deployRelease(service[0], service[ 1 ], null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* DEPLOY RELEASE METHODS*/
|
||||
|
||||
// collects all the components defined inside one or more yaml categories matching categoryList and invoke the deploy
|
||||
// collects all the components defined inside one or more yaml categories matching categoryList
|
||||
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 ->
|
||||
|
@ -389,16 +371,9 @@ def deployRelease(def categoryList, def yaml){
|
|||
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
|
||||
//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"; }}
|
||||
smartgears=(sg !=null ) ? sg[0] : null
|
||||
}else{
|
||||
releaseList += component_list?.collect {return "$it.name,$it.version" }
|
||||
}
|
||||
|
@ -407,58 +382,5 @@ def deployRelease(def categoryList, def yaml){
|
|||
}
|
||||
}
|
||||
}
|
||||
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;
|
||||
""")
|
||||
}
|
||||
}
|
||||
|
||||
deployReleaseJobs(releaseList, smartgears);
|
||||
}
|
403
README.html
403
README.html
File diff suppressed because one or more lines are too long
17
README.md
17
README.md
|
@ -20,27 +20,14 @@ Jenkins Pipeline script to manage one or more gCube components deployment
|
|||
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
|
||||
* DEPLOY_CATEGORY: (Related to release build) one or more Component group 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/)
|
||||
|
||||
## 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]]
|
||||
|
||||
|
||||
## Wiki doc
|
||||
|
||||
## Flow Chart
|
||||
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 253 KiB |
Binary file not shown.
Before Width: | Height: | Size: 194 KiB |
Binary file not shown.
Before Width: | Height: | Size: 403 KiB |
Loading…
Reference in New Issue