2023-04-28 11:16:08 +02:00
|
|
|
/**
|
|
|
|
* Given a git repository and a valid branch, a maven build is performed using jdk8
|
|
|
|
*
|
|
|
|
* Roberto Cirillo (ISTI-CNR)
|
|
|
|
*/
|
2022-09-20 12:22:01 +02:00
|
|
|
|
|
|
|
pipeline {
|
2023-01-12 16:53:12 +01:00
|
|
|
|
2022-09-21 15:40:55 +02:00
|
|
|
options {
|
|
|
|
ansiColor('xterm')
|
|
|
|
}
|
2022-09-20 12:29:59 +02:00
|
|
|
tools {
|
|
|
|
maven 'Maven 3-6-2'
|
|
|
|
jdk 'OpenJDK 8'
|
2022-09-20 12:22:01 +02:00
|
|
|
}
|
2022-09-20 12:29:59 +02:00
|
|
|
environment {
|
|
|
|
JAVA_HOME='/usr/lib/jvm/java-8-openjdk-amd64'
|
2022-09-21 10:34:38 +02:00
|
|
|
GIT_URL= "${params.GIT_URL}"
|
2022-09-21 14:27:56 +02:00
|
|
|
GIT_BRANCH="${params.GIT_BRANCH.split('/').size() > 1 ? params.GIT_BRANCH.split('/')[1..-1].join('/') : params.GIT_BRANCH}"
|
2023-01-12 15:54:48 +01:00
|
|
|
gcube_settings="${params.gcube_settings}"
|
|
|
|
local_repo="${params.local_repo}"
|
2024-03-20 16:19:30 +01:00
|
|
|
exec_label="${params.exec_label}"
|
2022-09-20 12:22:01 +02:00
|
|
|
}
|
2022-09-21 09:59:02 +02:00
|
|
|
parameters {
|
|
|
|
string(name: 'GIT_URL',
|
|
|
|
defaultValue: '',
|
|
|
|
description: 'git url')
|
2022-09-21 10:34:06 +02:00
|
|
|
string(name: 'GIT_BRANCH',
|
|
|
|
defaultValue: '',
|
|
|
|
description: 'git branch')
|
2023-01-12 15:54:48 +01:00
|
|
|
string(name: 'gcube_settings',
|
|
|
|
defaultValue: 'settings.xml',
|
|
|
|
description: 'the maven settings for gcube')
|
|
|
|
string(name: 'local_repo',
|
|
|
|
defaultValue: 'repository',
|
|
|
|
description: 'The location of the local repository')
|
|
|
|
string(name: 'exec_label',
|
|
|
|
defaultValue: 'CI',
|
2023-01-20 15:31:10 +01:00
|
|
|
description: 'Run on all nodes matching the label')
|
|
|
|
string(name: 'build_options',
|
|
|
|
defaultValue: '',
|
2023-04-28 11:33:58 +02:00
|
|
|
description: 'Additional options for Maven.')
|
|
|
|
string(name: 'maven_goal',
|
|
|
|
defaultValue: 'clean deploy',
|
|
|
|
description: 'maven goal. Useful if deploy is not needed')
|
2022-09-21 09:59:02 +02:00
|
|
|
}
|
2023-01-12 16:53:12 +01:00
|
|
|
agent
|
|
|
|
{
|
|
|
|
node
|
|
|
|
{
|
|
|
|
label "${exec_label}"
|
|
|
|
}
|
|
|
|
}
|
2022-09-20 12:29:59 +02:00
|
|
|
stages {
|
|
|
|
stage('Checkout git project') {
|
|
|
|
steps {
|
2022-09-20 14:44:09 +02:00
|
|
|
echo " env GIT_URL: ${env.GIT_URL}"
|
2022-09-20 15:55:20 +02:00
|
|
|
echo " env GIT_BRANCH: ${env.GIT_BRANCH}"
|
2022-09-20 14:46:14 +02:00
|
|
|
echo " param GIT_URL: ${params.GIT_URL}"
|
2022-09-21 10:32:35 +02:00
|
|
|
echo " param GIT_BRANCH: ${params.GIT_BRANCH}"
|
2022-09-20 14:44:09 +02:00
|
|
|
echo " GIT_URL: ${GIT_URL}"
|
2022-09-20 16:01:31 +02:00
|
|
|
echo " GIT_BRANCH: ${GIT_BRANCH}"
|
2022-09-21 10:38:18 +02:00
|
|
|
git branch: "${env.GIT_BRANCH}", credentialsId: '88b54962-1c0e-49cb-8155-22276860f346', url: "${GIT_URL}"
|
2022-09-20 12:29:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
stage('Build the job') {
|
|
|
|
steps {
|
2023-04-28 11:33:58 +02:00
|
|
|
sh 'mvn --settings $MAVEN_CONFIG_FOLDER/$gcube_settings -Dmaven.repo.local=$MAVEN_CONFIG_FOLDER/$local_repo $build_options dependency:tree $maven_goal'
|
2022-09-20 12:29:59 +02:00
|
|
|
}
|
2022-09-20 12:22:01 +02:00
|
|
|
}
|
2022-09-20 14:14:56 +02:00
|
|
|
|
2022-09-20 14:15:50 +02:00
|
|
|
stage('Clean') {
|
|
|
|
steps{
|
2024-11-06 12:27:37 +01:00
|
|
|
sh "mvn --settings $MAVEN_CONFIG_FOLDER/$gcube_settings -Dmaven.repo.local=$MAVEN_CONFIG_FOLDER/$local_repo clean"
|
2024-11-06 14:25:51 +01:00
|
|
|
sh "rm -Rf $MAVEN_CONFIG_FOLDER/../workspace/gCubeBuild/src/main/webapp/*"
|
2022-09-20 14:15:50 +02:00
|
|
|
}
|
|
|
|
}
|
2022-09-20 12:22:01 +02:00
|
|
|
}
|
2023-04-28 11:16:08 +02:00
|
|
|
// post-build actions
|
2022-09-20 12:22:01 +02:00
|
|
|
post {
|
|
|
|
success {
|
2022-09-20 12:29:59 +02:00
|
|
|
echo 'The gCubeBuild pipeline worked!'
|
2024-11-28 12:26:48 +01:00
|
|
|
emailext to: 'jenkinsbuilds@d4science.org',
|
2022-09-20 12:29:59 +02:00
|
|
|
subject: "[Jenkins gCubeBuild Pipeline] build ${currentBuild.fullDisplayName} worked",
|
2022-09-20 12:22:01 +02:00
|
|
|
body: "Build time: ${currentBuild.durationString}. See ${env.BUILD_URL}"
|
|
|
|
}
|
|
|
|
failure {
|
2022-09-20 12:29:59 +02:00
|
|
|
echo 'The gCubeBuild pipeline has failed'
|
2022-09-20 12:22:01 +02:00
|
|
|
emailext attachLog: true,
|
2024-11-28 12:26:48 +01:00
|
|
|
to: 'jenkinsbuilds@d4science.org',
|
2022-09-20 14:28:30 +02:00
|
|
|
subject: "[Jenkins DockerPipeline D4S] build ${currentBuild.fullDisplayName} failed",
|
2022-09-20 12:22:01 +02:00
|
|
|
body: "Something is wrong with ${env.BUILD_URL}"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|