Compare commits

3 Commits
main ... main

Author SHA1 Message Date
79f311cfd5 Update Jenkinsfile 2026-02-14 06:17:31 +00:00
0a288b1971 updated jenkinsfile 2026-02-14 06:13:12 +00:00
1eb71897c4 updated jenkinsfile 2026-02-14 06:10:21 +00:00

68
Jenkinsfile vendored
View File

@@ -2,13 +2,10 @@ pipeline {
agent any agent any
environment { environment {
// --- Shared Configuration --- HARBOR_URL = 'harbor.myriadcara.com'
HARBOR_URL = 'harbor.example.com' HARBOR_PROJECT = 'todo-app'
HARBOR_PROJECT = 'my-todo-app'
HARBOR_CREDS = 'harbor-credentials-id' HARBOR_CREDS = 'harbor-credentials-id'
K8S_CREDENTIALS_ID = 'k8s-kubeconfig' K8S_CREDENTIALS_ID = 'kubeconfig'
// Build Tag
IMAGE_TAG = "${env.BUILD_ID}" IMAGE_TAG = "${env.BUILD_ID}"
} }
@@ -24,9 +21,11 @@ pipeline {
stages { stages {
stage('Backend: Test') { stage('Backend: Test') {
steps { steps {
dir("${env.DIR}") { container('node') {
sh 'npm install' dir("${env.DIR}") {
sh 'npm test || true' sh 'npm install'
sh 'npm test || true'
}
} }
} }
} }
@@ -35,16 +34,20 @@ pipeline {
dir("${env.DIR}") { dir("${env.DIR}") {
script { script {
// Build & Push // Build & Push
sh "docker build -t ${FULL_IMAGE_PATH} ." container('docker') {
withCredentials([usernamePassword(credentialsId: "${HARBOR_CREDS}", usernameVariable: 'USER', passwordVariable: 'PASS')]) { sh "docker build -t ${FULL_IMAGE_PATH} ."
sh "docker login ${HARBOR_URL} -u ${USER} -p ${PASS}" withCredentials([usernamePassword(credentialsId: "${HARBOR_CREDS}", usernameVariable: 'USER', passwordVariable: 'PASS')]) {
sh "docker push ${FULL_IMAGE_PATH}" sh "docker login ${HARBOR_URL} -u ${USER} -p ${PASS}"
sh "docker push ${FULL_IMAGE_PATH}"
}
} }
// K8s Deploy // K8s Deploy
sh "sed 's|IMAGE_PATH_PLACEHOLDER|${FULL_IMAGE_PATH}|g' k8s-deployment.yaml > backend-k8s-applied.yaml" container('kubectl') {
sh "kubectl apply -f backend-k8s-applied.yaml" sh "sed 's|IMAGE_PATH_PLACEHOLDER|${FULL_IMAGE_PATH}|g' k8s-deployment.yaml > backend-k8s-applied.yaml"
sh "kubectl rollout status deployment/${SERVICE_NAME}" sh "kubectl apply -f backend-k8s-applied.yaml"
sh "kubectl rollout status deployment/${SERVICE_NAME}"
}
} }
} }
} }
@@ -61,9 +64,11 @@ pipeline {
stages { stages {
stage('Frontend: Test') { stage('Frontend: Test') {
steps { steps {
dir("${env.DIR}") { container('node') {
sh 'npm install' dir("${env.DIR}") {
sh 'npm test || true' sh 'npm install'
sh 'npm test || true'
}
} }
} }
} }
@@ -72,16 +77,20 @@ pipeline {
dir("${env.DIR}") { dir("${env.DIR}") {
script { script {
// Build & Push // Build & Push
sh "docker build -t ${FULL_IMAGE_PATH} ." container('docker') {
withCredentials([usernamePassword(credentialsId: "${HARBOR_CREDS}", usernameVariable: 'USER', passwordVariable: 'PASS')]) { sh "docker build -t ${FULL_IMAGE_PATH} ."
sh "docker login ${HARBOR_URL} -u ${USER} -p ${PASS}" withCredentials([usernamePassword(credentialsId: "${HARBOR_CREDS}", usernameVariable: 'USER', passwordVariable: 'PASS')]) {
sh "docker push ${FULL_IMAGE_PATH}" sh "docker login ${HARBOR_URL} -u ${USER} -p ${PASS}"
sh "docker push ${FULL_IMAGE_PATH}"
}
} }
// K8s Deploy // K8s Deploy
sh "sed 's|IMAGE_PATH_PLACEHOLDER|${FULL_IMAGE_PATH}|g' k8s-deployment.yaml > frontend-k8s-applied.yaml" container('kubectl') {
sh "kubectl apply -f frontend-k8s-applied.yaml" sh "sed 's|IMAGE_PATH_PLACEHOLDER|${FULL_IMAGE_PATH}|g' k8s-deployment.yaml > frontend-k8s-applied.yaml"
sh "kubectl rollout status deployment/${SERVICE_NAME}" sh "kubectl apply -f frontend-k8s-applied.yaml"
sh "kubectl rollout status deployment/${SERVICE_NAME}"
}
} }
} }
} }
@@ -94,9 +103,10 @@ pipeline {
post { post {
always { always {
sh "docker logout ${HARBOR_URL} || true" container('docker') {
// Cleanup temporary manifest files sh "docker logout ${HARBOR_URL} || true"
}
sh "rm -f backend/backend-k8s-applied.yaml frontend/frontend-k8s-applied.yaml" sh "rm -f backend/backend-k8s-applied.yaml frontend/frontend-k8s-applied.yaml"
} }
} }
} }