gCubeDeployer/Jenkinsfile

126 lines
4.0 KiB
Plaintext
Raw Normal View History

2022-04-22 15:38:43 +02:00
#!groovy
2022-04-22 11:41:05 +02:00
// related jenkins job: https://jenkins.d4science.org/job/gCubeDeployer/
2022-04-15 14:41:39 +02:00
pipeline {
agent {
label 'CD'
}
2022-04-15 15:23:26 +02:00
triggers {
2022-04-22 11:41:05 +02:00
// once a day on the 1st and 15th of every month
cron 'H H 1,15 * *'
2022-04-15 15:23:26 +02:00
}
//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')
2022-04-15 14:41:39 +02:00
environment {
AGENT_ROOT_FOLDER = "${agent_root_folder}"
2022-04-22 15:38:43 +02:00
DEPLOY_FILE = "${agent_deploy_file}/deploy.txt"
2022-04-15 14:41:39 +02:00
}
stages {
stage('initialize environment') {
steps {
sh '''
date=`date`
2022-04-15 14:59:34 +02:00
echo "#Build ${PIPELINE_BUILD_NUMBER},,"
2022-04-15 14:41:39 +02:00
'''
}
}
2022-04-15 15:06:25 +02:00
stage('Deploy from system') {
2022-04-15 14:41:39 +02:00
when{
allOf{
2022-04-15 15:45:23 +02:00
triggeredBy 'TimerTrigger'
environment name: 'IS_CRON', value: True
2022-04-15 14:41:39 +02:00
}
}
steps {
2022-04-15 17:20:46 +02:00
echo 'Cron build enabled. Deploy from system ongoing'
2022-04-22 15:38:43 +02:00
echo 'Components to deploy:'
2022-04-22 15:42:12 +02:00
cat "${DEPLOY_FILE}"
2022-04-22 15:38:43 +02:00
script {
2022-04-22 15:40:15 +02:00
def length="wc -l ${DEPLOY_FILE}"
2022-04-22 15:38:43 +02:00
for (int i = 0; i < length ; ++i) {
2022-04-22 15:42:12 +02:00
echo "Component $i+1: " < "${DEPLOY_FILE}"
2022-04-22 15:38:43 +02:00
}
}
2022-04-15 14:41:39 +02:00
}
}
2022-04-22 16:03:08 +02:00
stage('Nothing to do by System ') {
2022-04-15 14:41:39 +02:00
when{
2022-04-15 15:49:41 +02:00
allOf{
2022-04-15 16:04:19 +02:00
triggeredBy 'TimerTrigger'
environment name: 'IS_CRON', value: False
2022-04-15 15:49:41 +02:00
}
2022-04-15 14:41:39 +02:00
}
steps {
2022-04-15 17:20:46 +02:00
echo 'Do Nothing: cron build disabled'
2022-04-15 14:41:39 +02:00
}
}
2022-04-22 16:03:08 +02:00
stage('Nothing to do by Job ') {
when{
environment name: 'IS_CRON', value: True
anyOf{
triggeredBy 'BuildUpstreamCause'
triggeredBy 'UpstreamCause'
}
}
steps {
echo 'Do Nothing: cron build disabled'
}
}
2022-04-22 16:03:08 +02:00
stage('Add new pending deploy ') {
2022-04-15 15:57:10 +02:00
when{
environment name: 'IS_CRON', value: True
2022-04-15 16:26:45 +02:00
anyOf{
2022-04-15 16:04:19 +02:00
triggeredBy 'BuildUpstreamCause'
2022-04-15 16:26:45 +02:00
triggeredBy 'UpstreamCause'
2022-04-15 15:57:10 +02:00
}
}
steps {
2022-04-15 17:20:46 +02:00
echo "Cron build enabled. New deploy of ${params.TRIGGER_JOB} - ${params.TRIGGER_VERSION} appended to the deploy file"
2022-04-22 15:38:43 +02:00
echo "${params.TRIGGER_JOB} - ${params.TRIGGER_VERSION}" >> $DEPLOY_FILE
2022-04-15 15:57:10 +02:00
}
}
2022-04-15 15:06:25 +02:00
stage('Deploy from job ') {
when{
2022-04-15 16:26:45 +02:00
environment name: 'IS_CRON', value: 'False'
anyOf{
2022-04-15 16:04:19 +02:00
triggeredBy 'BuildUpstreamCause'
2022-04-15 16:26:45 +02:00
triggeredBy 'UpstreamCause'
2022-04-15 15:57:10 +02:00
}
2022-04-15 15:06:25 +02:00
}
steps {
2022-04-15 17:20:46 +02:00
echo "Cron build disabled. New deploy of ${params.TRIGGER_JOB} - ${params.TRIGGER_VERSION} ongoing"
2022-04-15 15:06:25 +02:00
}
}
2022-04-15 14:41:39 +02:00
}
post {
always {
script {
sh '''
echo ' jobs currently appended:'
'''
2022-04-15 15:06:25 +02:00
//cat ./${ACTION_DEPLOY_FILE}.csv
2022-04-15 14:41:39 +02:00
}
}
success {
echo 'The deploy pipeline worked!'
2022-04-15 15:26:43 +02:00
emailext attachLog: true,//attachmentsPattern: "**/${ACTION_DEPLOY_FILE}.csv",
2022-04-15 14:41:39 +02:00
to: 'roberto.cirillo@isti.cnr.it',
2022-04-15 15:27:56 +02:00
subject: "Deploy report",
2022-04-15 14:41:39 +02:00
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}"
}
}
}