From a36a3b4c902e25afc82985a2d9a79f5bcc9abe77 Mon Sep 17 00:00:00 2001 From: Roberto Cirillo Date: Fri, 15 Apr 2022 14:41:39 +0200 Subject: [PATCH] fix sintax --- Jenkinsfile | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 85 insertions(+), 5 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index fc2df3c..1f4485f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -6,10 +6,6 @@ * Roberto Cirillo (ISTI-CNR) */ - def agent_root_folder = '/var/lib/jenkins/.m2' - -//locate the deploy file - def agent_deploy_file = // "${action_root}/${action_file}" //locate the ansible home //def agent_ansible_home= '${agent_root_folder}/path/to/ansible'; @@ -133,6 +129,90 @@ body: "Something is wrong with ${env.BUILD_URL}" } - } + } } +#!groovy + +def agent_root_folder = '/var/lib/jenkins/.m2' + +//locate the deploy file +def agent_deploy_file = // "${action_root}/${action_file}" + + +pipeline { + + agent { + label 'CD' + triggers { + //once in every two hours slot between 9 AM and 5 PM every weekday (perhaps at 10:38 AM, 12:38 PM, 2:38 PM, 4:38 PM) + cron('H H(9-16)/2 * * 1-5') + } + } + + environment { + AGENT_ROOT_FOLDER = "${agent_root_folder}" + AGENT_DEPLOY_FILE = "${agent_deploy_file}" + } + stages { + stage('initialize environment') { + steps { + sh ''' + date=`date` + echo "#Build ${PIPELINE_BUILD_NUMBER},," > $ACTION_REPORT + echo "#StartTime ${date},," >> $ACTION_REPORT + echo "Project,Repo,Result" >> $ACTION_REPORT + ''' + } + } + stage('clone and exec') { + when{ + beforeAgent true + allOf{ + triggeredBy 'TimeTrigger' + environment name: 'IS_CRON', value: 'True' + } + } + steps { + echo 'Deploy from system properly triggered' + } + } + stage('Planning new deploy') { + beforeAgent true + when{ + environment name: 'IS_CRON', value: 'True' + } + steps { + echo 'New deploy of ${job} appended to the deploy file' + } + } + + } + post { + always { + script { + sh ''' + echo ' jobs currently appended:' + cat ./${ACTION_DEPLOY_FILE}.csv + ''' + } + } + success { + echo 'The deploy pipeline worked!' + + emailext attachmentsPattern: "**/${ACTION_DEPLOY_FILE}.csv", + to: 'roberto.cirillo@isti.cnr.it', + subject: "Deploy report (build #${PIPELINE_BUILD_NUMBER})", + 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', + subject: "[Jenkins deploy D4S] deploy ${currentBuild.fullDisplayName} failed", + body: "Something is wrong with ${env.BUILD_URL}" + } + + } +} +