add cleanup deploy file

This commit is contained in:
Roberto Cirillo 2022-04-28 10:27:36 +02:00
parent d1bcc91df4
commit 00f1e7b869
1 changed files with 28 additions and 1 deletions

29
Jenkinsfile vendored
View File

@ -10,8 +10,10 @@
def agent_root_folder = '/var/lib/jenkins' def agent_root_folder = '/var/lib/jenkins'
def agent_deploy_filename = 'deploy.csv' def agent_deploy_filename = 'deploy.csv'
def agent_deploy_backup_filename = 'deploy.bck'
def deployList def deployList
def backupList
if (params.deployFile) { if (params.deployFile) {
println "Using custom deploy file" println "Using custom deploy file"
deployList = params.deployFile deployList = params.deployFile
@ -21,6 +23,7 @@ if (params.deployFile) {
deployList = agent_root_folder+'/'+agent_deploy_filename; deployList = agent_root_folder+'/'+agent_deploy_filename;
println "Load from local file ${deployList}" println "Load from local file ${deployList}"
} }
backupList = agent_root_folder+'/'+agent_deploy_backup_filename;
pipeline { pipeline {
agent { agent {
@ -40,6 +43,7 @@ pipeline {
environment { environment {
AGENT_ROOT_FOLDER = "${agent_root_folder}" AGENT_ROOT_FOLDER = "${agent_root_folder}"
DEPLOY_FILE = "${agent_root_folder}/${agent_deploy_filename}" DEPLOY_FILE = "${agent_root_folder}/${agent_deploy_filename}"
BACKUP_FILE = "${agent_root_folder}/${agent_deploy_backup_filename}"
TRIGGER_JOB= "${params.TRIGGER_JOB}" TRIGGER_JOB= "${params.TRIGGER_JOB}"
TRIGGER_VERSION= "${params.TRIGGER_VERSION}" TRIGGER_VERSION= "${params.TRIGGER_VERSION}"
} }
@ -69,8 +73,16 @@ pipeline {
for (component in components) { for (component in components) {
println "Deploy on going of component: $component" println "Deploy on going of component: $component"
} }
new File(${DEPLOY_FILE}).delete();
} }
sh '''
echo "cleanup $DEPLOY_FILE"
if [ -f ${DEPLOY_BACKUP ]; then
echo "backup found: $DEPLOY_BACKUP going to replace it"
rm ${DEPLOY_BACKUP}
mv $DEPLOY_FILE $DEPLOY_BACKUP
touch $DEPLOY_FILE
'''
} }
} }
stage('Nothing to do by System ') { stage('Nothing to do by System ') {
@ -95,6 +107,7 @@ pipeline {
steps { steps {
sh ''' sh '''
echo "Cron build enabled. New deploy of ${TRIGGER_JOB} - ${TRIGGER_VERSION} will be added to the deploy file" echo "Cron build enabled. New deploy of ${TRIGGER_JOB} - ${TRIGGER_VERSION} will be added to the 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."
else else
@ -173,3 +186,17 @@ def appendToFile(String fileName, String line) {
writeFile file: fileName, text: current + "\n" + line writeFile file: fileName, text: current + "\n" + line
} }
/**
* Appends the footer to the deploy file.
*/
def appendFooter( def File) {
def now = new Date()
sh("""
echo "" >> $File
echo "---" >> $File
echo "*generated by the gCubeDeploy pipeline >> $File
echo "" >> $File
echo "*last update $now*" >> $File
""")
}