From ff2310679430993a64da486e280efd2d79ae1979 Mon Sep 17 00:00:00 2001 From: Mihailo Marcetic Date: Wed, 12 Feb 2025 10:00:29 +0100 Subject: [PATCH] Add Jenkinsfile --- Jenkinsfile | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 000000000..0b6adbaf5 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,54 @@ +pipeline { + agent any + + environment { + // Define environment variables + DOCKER_REGISTRY = "docker.io" + DOCKER_IMAGE = "mmarcetic/main" + DOCKER_CREDENTIALS = "Docker_hub" + } + + stages { + stage('Checkout') { + steps { + // Checkout the code from the repository + checkout scm + } + } + + stage('Build Docker Image') { + steps { + script { + // Build the Docker image + sh 'docker build -t ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:latest .' + } + } + } + + stage('Push Docker Image') { + steps { + script { + //Login to the Docker repository + docker.withRegistry('https://${DOCKER_REGISTRY}', "${DOCKER_CREDENTIALS}") { + // Push the Docker image to the registry + sh 'docker push ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:latest' + } + } + } + } + } + + post { + always { + // Clean up Docker images after the job is done + sh 'docker rmi ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:latest || true' + } + success { + echo 'Docker image built and pushed successfully.' + } + failure { + echo 'Pipeline failed!' + } + } +} +