Skip to content

Commit

Permalink
Update Jenkinsfile
Browse files Browse the repository at this point in the history
  • Loading branch information
Hellal1997 committed Aug 10, 2024
1 parent ccba962 commit 535f2d8
Showing 1 changed file with 32 additions and 14 deletions.
46 changes: 32 additions & 14 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,56 @@ pipeline {
agent any

parameters {
string(name: 'IMAGE_TAG', defaultValue: 'latest', description: 'Docker image tag')
string(name: 'DOCKER_TAG', defaultValue: 'latest', description: 'Tag for the Docker image')
}

environment {
// Define Docker image name
DOCKER_IMAGE_NAME = 'your-docker-image-name'
// Define Docker registry credentials ID
DOCKER_CREDENTIALS_ID = 'your-docker-credentials-id'
}

triggers {
// Trigger the build on changes to the Test branch
scm('H/5 * * * *')
}

stages {
stage('Checkout') {
stage('Checkout Code') {
steps {
checkout scm
script {
// Debugging: List files in workspace
sh 'ls -la'
}
// Checkout code from Git repository
git credentialsId: 'your-github-credentials-id', url: 'https://github.com/your-repo.git', branch: 'Test'
}
}

stage('Build Docker Image') {
steps {
script {
def imageName = "mohamedhellal/jenkins/jenkins"
def imageTag = "${params.latest}"

// Build Docker image
docker.build("${imageName}:${imageTag}", "-f Dockerfile .")
// Build Docker image with the parameterized tag
def image = docker.build("${DOCKER_IMAGE_NAME}:${params.DOCKER_TAG}", "-f Dockerfile .")
}
}
}

stage('Push Docker Image') {
steps {
script {
docker.withRegistry('https://index.docker.io/v1/', 'docker-hub-credentials') {
docker.image("mohamedhellal/jenkins/jenkins:${params.latest}").push("${params.latest}")
// Log in to Docker registry and push Docker image
docker.withRegistry('https://index.docker.io/v1/', DOCKER_CREDENTIALS_ID) {
docker.image("${DOCKER_IMAGE_NAME}:${params.DOCKER_TAG}").push("${params.DOCKER_TAG}")
}
}
}
}
}

post {
always {
// Clean up Docker images to save space
script {
sh 'docker system prune -f'
}
}
}
}

0 comments on commit 535f2d8

Please sign in to comment.