From 705c5b16890ee7e666539b611be689bcbd7dd56f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Mon, 8 Nov 2021 14:45:43 +0100 Subject: [PATCH] add Jenkinsfile for Docker image CI builds MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jakub SokoĊ‚owski --- Jenkinsfile | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..034555f --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,53 @@ +pipeline { + agent { label 'linux' } + + parameters { + booleanParam( + name: 'DEPLOY', + description: 'Enable to deploye the Docker image.', + defaultValue: false, + ) + } + + options { + timestamps() + disableConcurrentBuilds() + /* manage how many builds we keep */ + buildDiscarder(logRotator( + numToKeepStr: '10', + daysToKeepStr: '30', + )) + } + + environment { + IMAGE_NAME = "statusteam/telemetry" + IMAGE_DEFAULT_TAG = "${env.GIT_COMMIT.take(7)}" + IMAGE_DEPLOY_TAG = "deploy" + } + + stages { + stage('Build') { steps { script { + image = docker.build( + "${env.IMAGE_NAME}:${env.IMAGE_DEFAULT_TAG}" + ) + } } } + + stage('Push') { steps { script { + withDockerRegistry([ + credentialsId: "dockerhub-statusteam-auto" + ]) { + image.push() + } + } } } + + stage('Deploy') { + when { expression { params.DEPLOY } } + steps { script { + withDockerRegistry([ + credentialsId: "dockerhub-statusteam-auto" + ]) { + image.push(env.IMAGE_DEPLOY_TAG) + } + } } } + } // stages +} // pipeline