From dda4cb40e00aa0473a8f59017f3097120e619dc3 Mon Sep 17 00:00:00 2001 From: Francia Csaba Date: Thu, 30 May 2024 12:44:32 +0200 Subject: [PATCH] Updated Jenkinsfile to build docker container --- Jenkinsfile | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index b13825f..11e6b50 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -4,6 +4,11 @@ pipeline { GITEA_CREDS = credentials('AMARILLO-JENKINS-GITEA-USER') PYPI_CREDS = credentials('AMARILLO-JENKINS-PYPI-USER') TWINE_REPO_URL = "https://git.gerhardt.io/api/packages/amarillo/pypi" + DOCKER_REGISTRY_URL = 'https://git.gerhardt.io' + OWNER = 'amarillo' + IMAGE_NAME = 'amarillo-enhancer' + DISTRIBUTION = '0.2' + TAG = "${DISTRIBUTION}.${BUILD_NUMBER}" } stages { stage('Create virtual environment') { @@ -44,5 +49,31 @@ pipeline { sh 'python3 -m twine upload --verbose --username $PYPI_CREDS_USR --password $PYPI_CREDS_PSW ./dist/*' } } + stage('Build docker image') { + when { + branch 'main' + } + steps { + echo 'Building image' + script { + docker.build("${OWNER}/${IMAGE_NAME}:${TAG}") + } + } + } + stage('Push image to container registry') { + when { + branch 'main' + } + steps { + echo 'Pushing image to registry' + script { + docker.withRegistry(DOCKER_REGISTRY_URL, 'AMARILLO-JENKINS-GITEA-USER'){ + def image = docker.image("${OWNER}/${IMAGE_NAME}:${TAG}") + image.push() + image.push('latest') + } + } + } + } } } \ No newline at end of file