forked from gitea_admin/simple-node
frontend
This commit is contained in:
61
frontend/Jenkinsfile
vendored
Normal file
61
frontend/Jenkinsfile
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
pipeline {
|
||||
agent any
|
||||
|
||||
environment {
|
||||
// --- Harbor Configuration ---
|
||||
HARBOR_URL = 'harbor.example.com'
|
||||
HARBOR_PROJECT = 'my-todo-app'
|
||||
IMAGE_NAME = 'todo-frontend'
|
||||
HARBOR_CREDS = 'harbor-credentials-id'
|
||||
|
||||
// --- Kubernetes Configuration ---
|
||||
K8S_CREDENTIALS_ID = 'k8s-kubeconfig'
|
||||
// ----------------------------
|
||||
|
||||
IMAGE_TAG = "${env.BUILD_ID}"
|
||||
FULL_IMAGE_PATH = "${HARBOR_URL}/${HARBOR_PROJECT}/${IMAGE_NAME}:${IMAGE_TAG}"
|
||||
}
|
||||
|
||||
stages {
|
||||
stage('Install & Test') {
|
||||
steps {
|
||||
sh 'npm install'
|
||||
sh 'npm test || true'
|
||||
}
|
||||
}
|
||||
|
||||
stage('Build & Push to Harbor') {
|
||||
steps {
|
||||
script {
|
||||
sh "docker build -t ${FULL_IMAGE_PATH} ."
|
||||
withCredentials([usernamePassword(credentialsId: "${HARBOR_CREDS}", usernameVariable: 'USER', passwordVariable: 'PASS')]) {
|
||||
sh "docker login ${HARBOR_URL} -u ${USER} -p ${PASS}"
|
||||
sh "docker push ${FULL_IMAGE_PATH}"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('Deploy to Kubernetes') {
|
||||
steps {
|
||||
script {
|
||||
// 1. Replace placeholder in YAML
|
||||
sh "sed 's|IMAGE_PATH_PLACEHOLDER|${FULL_IMAGE_PATH}|g' k8s-deployment.yaml > frontend-k8s-applied.yaml"
|
||||
|
||||
// 2. Apply manifest
|
||||
sh "kubectl apply -f frontend-k8s-applied.yaml"
|
||||
|
||||
// 3. Verify rollout
|
||||
sh "kubectl rollout status deployment/todo-frontend"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
post {
|
||||
always {
|
||||
sh "docker logout ${HARBOR_URL}"
|
||||
sh "rm -f frontend-k8s-applied.yaml"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user