gCubeDeployer/Jenkinsfile

139 lines
4.2 KiB
Plaintext
Raw Normal View History

2022-04-14 16:26:13 +02:00
#!groovy
2022-04-14 15:28:19 +02:00
2022-04-14 16:26:13 +02:00
/**
* Deploy gCube components by Ansible
*
* Roberto Cirillo (ISTI-CNR)
*/
2022-04-15 14:31:21 +02:00
def agent_root_folder = '/var/lib/jenkins/.m2'
2022-04-14 16:26:13 +02:00
//locate the deploy file
2022-04-15 14:31:21 +02:00
def agent_deploy_file = // "${action_root}/${action_file}"
2022-04-14 16:26:13 +02:00
//locate the ansible home
2022-04-14 17:45:29 +02:00
//def agent_ansible_home= '${agent_root_folder}/path/to/ansible';
2022-04-14 16:26:13 +02:00
//println "Querying ${actionURL}"
2022-04-14 15:28:19 +02:00
2022-04-15 14:31:21 +02:00
pipeline {
2022-04-14 16:26:13 +02:00
agent {
label 'CD'
triggers {
2022-04-14 17:08:51 +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-14 15:28:19 +02:00
}
}
2022-04-14 16:26:13 +02:00
environment {
AGENT_ROOT_FOLDER = "${agent_root_folder}"
AGENT_DEPLOY_FILE = "${agent_deploy_file}"
2022-04-14 15:28:19 +02:00
}
2022-04-14 16:26:13 +02:00
parameters {
string(name: 'git_root',
defaultValue: 'https://code-repo.d4science.org/TestActions/',
description: 'The root URL of the repositories')
string(name: 'repo_list',
defaultValue: 'https://code-repo.d4science.org/gCubeCI/gCubeActions/raw/branch/master/repos/TestActions_all_sorted.txt',
description: 'The file with the list of repositories to update')
string(name: 'action_root',
defaultValue: 'https://code-repo.d4science.org/gCubeCI/gCubeActions/raw/branch/master/',
description: 'The root URL of the Bash fragment to execute.')
string(name: 'action_file',
defaultValue: '',
description: 'The relative path of the Bash fragment to execute.')
string(name: 'filter_with',
defaultValue: '',
description: 'If not empty, only actions including this filter in their output will be reported.')
2022-04-14 15:28:19 +02:00
}
2022-04-14 16:26:13 +02:00
stages {
stage('Initialize env') {
steps {
sh '''
date=`date`
2022-04-14 17:08:51 +02:00
echo "#Build ${PIPELINE_BUILD_NUMBER},,"
echo "#StartTime ${date},,"
echo "Project,Repo,Result"
2022-04-14 16:26:13 +02:00
'''
}
}
stage('Deploy from system') {
when{
beforeAgent true
allOf{
triggeredBy 'TimeTrigger'
environment name: 'IS_CRON', value: 'True'
}
}
steps {
echo 'Deploy from system properly triggered'
}
}
stage('Deploy from system disabled') {
when{
beforeAgent true
allOf{
triggeredBy 'TimeTrigger'
environment name: 'IS_CRON', value: 'False'
}
}
steps {
echo 'Deploy from system disabled. Do nothing.'
}
}
stage('Deploy from Job') {
beforeAgent true
when{
environment name: 'IS_CRON', value: 'False'
}
steps {
echo 'Deploy from Job started'
}
}
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-build actions
2022-04-14 15:28:19 +02:00
post {
2022-04-14 16:26:13 +02:00
always {
script {
sh '''
echo ' jobs currently appended:'
cat ./${ACTION_DEPLOY_FILE}.csv
'''
}
}
2022-04-14 15:28:19 +02:00
success {
2022-04-14 16:26:13 +02:00
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}. "
2022-04-14 15:28:19 +02:00
}
failure {
2022-04-14 16:26:13 +02:00
echo 'The deploy pipeline has failed'
2022-04-14 15:28:19 +02:00
emailext attachLog: true,
2022-04-14 16:26:13 +02:00
to: 'roberto.cirillo@isti.cnr.it',
subject: "[Jenkins deploy D4S] deploy ${currentBuild.fullDisplayName} failed",
2022-04-14 15:28:19 +02:00
body: "Something is wrong with ${env.BUILD_URL}"
}
2022-04-14 16:26:13 +02:00
2022-04-14 15:28:19 +02:00
}
2022-04-15 14:31:21 +02:00
}
2022-04-14 16:26:13 +02:00