2022-04-15 14:41:39 +02:00
|
|
|
pipeline {
|
|
|
|
agent {
|
|
|
|
label 'CD'
|
|
|
|
}
|
2022-04-15 15:23:26 +02:00
|
|
|
triggers {
|
|
|
|
cron "*/10 * * * *"
|
|
|
|
}
|
|
|
|
//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}"
|
|
|
|
AGENT_DEPLOY_FILE = "${agent_deploy_file}"
|
|
|
|
}
|
|
|
|
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'
|
2022-04-15 14:41:39 +02:00
|
|
|
environment name: 'IS_CRON', value: 'True'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
steps {
|
|
|
|
echo 'Deploy from system properly triggered'
|
|
|
|
}
|
|
|
|
}
|
2022-04-15 16:04:19 +02:00
|
|
|
stage('Nothing to do ') {
|
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 16:04:19 +02:00
|
|
|
echo 'Do Nothing: cron disabled on agent'
|
2022-04-15 14:41:39 +02:00
|
|
|
}
|
|
|
|
}
|
2022-04-15 16:04:19 +02:00
|
|
|
stage('Add new pending deploy ') {
|
2022-04-15 15:57:10 +02:00
|
|
|
when{
|
2022-04-15 16:26:45 +02:00
|
|
|
environment name: 'IS_CRON', value: 'True'
|
|
|
|
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:13:43 +02:00
|
|
|
echo "New deploy of ${params.TRIGGER_JOB} - ${params.TRIGGER_VERSION} appended to the 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:13:43 +02:00
|
|
|
echo "New deploy of ${params.TRIGGER_JOB} - ${params.TRIGGER_VERSION}"
|
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}"
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|