Update 'Jenkinsfile'

add jenkinsfile
This commit is contained in:
Roberto Cirillo 2022-09-20 12:29:59 +02:00
parent 378b764b61
commit 2e9027ad61
1 changed files with 33 additions and 38 deletions

71
Jenkinsfile vendored
View File

@ -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}"
}