From 2e9027ad612bb18a520198254bb298a5d8b8fc22 Mon Sep 17 00:00:00 2001 From: Roberto Cirillo Date: Tue, 20 Sep 2022 12:29:59 +0200 Subject: [PATCH] Update 'Jenkinsfile' add jenkinsfile --- Jenkinsfile | 71 +++++++++++++++++++++++++---------------------------- 1 file changed, 33 insertions(+), 38 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 4ab75cb..f1e7552 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -5,44 +5,39 @@ pipeline { - agent { - label 'docker' - } - environment { - imagename = "" //TO FILL WITH THE RIGHT VALUE (RepositoryName) e.g. d4science/RepositoryName - registryCredential = 'e348bfab-5580-4db6-b0e0-d854966bde08' - dockerImage = '' - git_url='' // SET HERE THE URL OF YOUR NEW GIT PROJECT - } - stages { - stage('Cloning Git') { - steps { - git([url: git_url, branch: 'master', credentialsId: '88b54962-1c0e-49cb-8155-22276860f346']) - - } + agent { label 'CI'} + tools { + maven 'Maven 3-6-2' + jdk 'OpenJDK 8' } - stage('Building image') { - steps{ - script { - dockerImage = docker.build imagename + environment { + JAVA_HOME='/usr/lib/jvm/java-8-openjdk-amd64' + GIT_URL= "${params.GIT_URL}" + GIT_BRANCH= "${params.GIT_BRANCH}" + } + parameters { + string(name: 'GIT_URL', + defaultValue: '', + description: 'git url') + string(name: 'GIT_BRANCH', + defaultValue: '', + description: 'git branch') + } + stages { + stage('Checkout git project') { + steps { + git branch: '${params.GIT_BRANCH}', credentialsId: '88b54962-1c0e-49cb-8155-22276860f346', url: '${params.GIT_URL}' + } } - } - } - stage('Deploy Image') { - steps{ - script { - docker.withRegistry( '', registryCredential ) { - dockerImage.push("$BUILD_NUMBER") - dockerImage.push('latest') - - } + stage('Build the job') { + steps { + sh 'mvn --settings $MAVEN_CONFIG_FOLDER/$gcube_settings -Dmaven.repo.local=$MAVEN_CONFIG_FOLDER/$local_repo $build_options dependency:tree clean deploy' + } } - } } - stage('Remove Unused docker image') { + stage('Clean') { steps{ - sh "docker rmi $imagename:$BUILD_NUMBER" - sh "docker rmi $imagename:latest" + sh "mvn clean" } } @@ -50,15 +45,15 @@ pipeline { // post-build actions post { success { - echo 'The docker pipeline worked!' - emailext to: 'jenkinsbuilds@d4science.org', - subject: "[Jenkins DockerPipeline D4S] build ${currentBuild.fullDisplayName} worked", + echo 'The gCubeBuild pipeline worked!' + emailext to: 'roberto.cirillo@isti.cnr.it', + subject: "[Jenkins gCubeBuild Pipeline] build ${currentBuild.fullDisplayName} worked", body: "Build time: ${currentBuild.durationString}. See ${env.BUILD_URL}" } failure { - echo 'The docker pipeline has failed' + echo 'The gCubeBuild pipeline has failed' emailext attachLog: true, - to: 'jenkinsbuilds@d4science.org', + to: 'roberto.cirillo@isti.cnr.it', subject: "[Jenkins DockerPipeline D4S] build ${currentBuild.fullDisplayName} failed for image ${imagename}", body: "Something is wrong with ${env.BUILD_URL}" }