commit c64eb184769850118b032720c0faf88ae7722451 Author: gCubeSystem <> Date: Mon Apr 4 17:10:24 2022 +0200 Initial commit diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..4ab75cb --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,66 @@ +// REMEMBER TO FILL THE environment section with your values. +// the following filed should be filled: imagename, git_url +// REMEMBER to put your Dockerfile in the root folder of your project +// The related jenkinsjob template is here: + + +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']) + + } + } + stage('Building image') { + steps{ + script { + dockerImage = docker.build imagename + } + } + } + stage('Deploy Image') { + steps{ + script { + docker.withRegistry( '', registryCredential ) { + dockerImage.push("$BUILD_NUMBER") + dockerImage.push('latest') + + } + } + } + } + stage('Remove Unused docker image') { + steps{ + sh "docker rmi $imagename:$BUILD_NUMBER" + sh "docker rmi $imagename:latest" + + } + } + } + // post-build actions + post { + success { + echo 'The docker pipeline worked!' + emailext to: 'jenkinsbuilds@d4science.org', + subject: "[Jenkins DockerPipeline D4S] build ${currentBuild.fullDisplayName} worked", + body: "Build time: ${currentBuild.durationString}. See ${env.BUILD_URL}" + } + failure { + echo 'The docker pipeline has failed' + emailext attachLog: true, + to: 'jenkinsbuilds@d4science.org', + subject: "[Jenkins DockerPipeline D4S] build ${currentBuild.fullDisplayName} failed for image ${imagename}", + body: "Something is wrong with ${env.BUILD_URL}" + } + } +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..3332270 --- /dev/null +++ b/README.md @@ -0,0 +1,12 @@ +# Pipeline-Docker-Template + +This is a template useful for building docker images and push to dockerhub. +There is a jenkinsjob template on our jenkins with the same name. + + +## USAGE TIPS: + +* REMEMBER TO FILL the jenkinsfile environment section with your values. The following field should be properly filled: imagename, git_url +* REMEMBER TO PUT your Dockerfile in the root folder of your new project + +* You can find the related jenkinsjob template here: https://jenkins.d4science.org/job/Pipeline-Docker-Template/