Compare commits

..

2 commits

Author SHA1 Message Date
MMarceticGrid
5521d79d86
Merge 2f3a85b3a3 into 2aa53f929d 2025-03-07 09:15:56 +00:00
Mihailo
2f3a85b3a3 Add deployment and service for kind cluster 2025-03-07 10:13:26 +01:00
2 changed files with 6 additions and 84 deletions

79
Jenkinsfile vendored
View file

@ -4,9 +4,7 @@ pipeline {
environment { environment {
// Define environment variables // Define environment variables
DOCKER_REGISTRY = "docker.io" DOCKER_REGISTRY = "docker.io"
DOCKER_IMAGE_MAIN = 'mmarcetic/main' DOCKER_IMAGE = "mmarcetic/main"
DOCKER_IMAGE_MR = 'mmarcetic/mr'
GIT_COMMIT = sh(script: "git rev-parse --short HEAD", returnStdout: true).trim()
} }
stages { stages {
@ -17,88 +15,23 @@ pipeline {
} }
} }
stage('Set Docker Image') {
steps {
script {
// Set Docker image based on the branch name
if (env.BRANCH_NAME == 'main') {
env.DOCKER_IMAGE = DOCKER_IMAGE_MAIN
} else {
env.DOCKER_IMAGE = DOCKER_IMAGE_MR
}
echo "Using Docker image: ${env.DOCKER_IMAGE}"
}
}
}
stage('Checkstyle Report') {
when {
changeRequest()
}
steps {
script {
// Checkstyle with Gradle
sh './gradlew checkstyleMain'
archiveArtifacts artifacts: 'build/reports/checkstyle/*.xml', allowEmptyArchive: true
}
}
}
stage('Test') {
when {
changeRequest()
}
steps {
// Test using Gradle
sh './gradlew clean test'
}
}
stage('Build Without Tests') {
when {
changeRequest()
}
steps {
script {
// Build without tests using Gradle
sh './gradlew build -x test'
}
}
}
stage('Build Docker Image') { stage('Build Docker Image') {
steps { steps {
script { script {
// Build the Docker image // Build the Docker image
sh "docker build -t ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${GIT_COMMIT} ." def gitCommit = sh(script: "git rev-parse --short HEAD", returnStdout: true).trim()
sh "docker build -t ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${gitCommit} ."
} }
} }
} }
stage('Push Docker Image for Change Request') { stage('Push Docker Image') {
when {
changeRequest()
}
steps { steps {
script { script {
def gitCommit = sh(script: "git rev-parse --short HEAD", returnStdout: true).trim()
withCredentials([usernamePassword(credentialsId: "docker-login", usernameVariable: "DOCKER_USER", passwordVariable: "DOCKER_PASSWORD")]) { withCredentials([usernamePassword(credentialsId: "docker-login", usernameVariable: "DOCKER_USER", passwordVariable: "DOCKER_PASSWORD")]) {
sh "docker login -u ${DOCKER_USER} -p ${DOCKER_PASSWORD}" sh "docker login -u ${DOCKER_USER} -p ${DOCKER_PASSWORD}"
sh "docker push ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${GIT_COMMIT}" sh "docker push ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${gitCommit}"
}
}
}
}
stage('Push Docker Image for Main') {
when {
branch "main"
}
steps {
script {
withCredentials([usernamePassword(credentialsId: "docker-login", usernameVariable: "DOCKER_USER", passwordVariable: "DOCKER_PASSWORD")]) {
sh "docker login -u ${DOCKER_USER} -p ${DOCKER_PASSWORD}"
sh "docker push ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${GIT_COMMIT}"
} }
} }
} }

View file

@ -1,11 +0,0 @@
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
extraPortMappings:
- containerPort: 30950
hostPort: 30950
listenAddress: "127.0.0.1"
protocol: TCP