diff --git a/Jenkfile b/Jenkfile new file mode 100644 index 0000000..5dc5e2c --- /dev/null +++ b/Jenkfile @@ -0,0 +1,43 @@ +pipeline { + agent any + + environment { + DOCKERHUB_CREDENTIALS = credentials('dockerhub-credentials') // Jenkins credentials ID for Docker Hub + DOCKERHUB_REPO = 'samil88/frontend' + DOCKER_IMAGE_TAG = 'latest' + } + + stages { + stage('Clone Repository') { + steps { + // Clone your repository + checkout scm + } + } + + stage('Build Docker Image') { + steps { + script { + dockerImage = docker.build("${DOCKERHUB_REPO}:${DOCKER_IMAGE_TAG}") + } + } + } + + stage('Push Docker Image') { + steps { + script { + docker.withRegistry('https://index.docker.io/v1/', 'dockerhub-credentials') { + dockerImage.push() + } + } + } + } + } + + post { + always { + // Clean up Docker images to free up space + sh "docker rmi ${DOCKERHUB_REPO}:${DOCKER_IMAGE_TAG} || true" + } + } +}