forked from gitea_admin/simple-node
updated jenkinsfile
This commit is contained in:
24
Jenkinsfile
vendored
24
Jenkinsfile
vendored
@@ -1,14 +1,13 @@
|
|||||||
pipeline {
|
pipeline {
|
||||||
agent any
|
agent {
|
||||||
|
label 'build-agent' // This matches the label you configured
|
||||||
|
}
|
||||||
|
|
||||||
environment {
|
environment {
|
||||||
// --- Shared Configuration ---
|
HARBOR_URL = 'harbor.myriadcara.com' // Fixed your URL
|
||||||
HARBOR_URL = 'harbor.example.com'
|
|
||||||
HARBOR_PROJECT = 'my-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 = 'k8s-kubeconfig'
|
||||||
|
|
||||||
// Build Tag
|
|
||||||
IMAGE_TAG = "${env.BUILD_ID}"
|
IMAGE_TAG = "${env.BUILD_ID}"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,24 +23,29 @@ pipeline {
|
|||||||
stages {
|
stages {
|
||||||
stage('Backend: Test') {
|
stage('Backend: Test') {
|
||||||
steps {
|
steps {
|
||||||
|
container('node') {
|
||||||
dir("${env.DIR}") {
|
dir("${env.DIR}") {
|
||||||
sh 'npm install'
|
sh 'npm install'
|
||||||
sh 'npm test || true'
|
sh 'npm test || true'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
stage('Backend: Push & Deploy') {
|
stage('Backend: Push & Deploy') {
|
||||||
steps {
|
steps {
|
||||||
dir("${env.DIR}") {
|
dir("${env.DIR}") {
|
||||||
script {
|
script {
|
||||||
// Build & Push
|
// Build & Push
|
||||||
|
container('docker') {
|
||||||
sh "docker build -t ${FULL_IMAGE_PATH} ."
|
sh "docker build -t ${FULL_IMAGE_PATH} ."
|
||||||
withCredentials([usernamePassword(credentialsId: "${HARBOR_CREDS}", usernameVariable: 'USER', passwordVariable: 'PASS')]) {
|
withCredentials([usernamePassword(credentialsId: "${HARBOR_CREDS}", usernameVariable: 'USER', passwordVariable: 'PASS')]) {
|
||||||
sh "docker login ${HARBOR_URL} -u ${USER} -p ${PASS}"
|
sh "docker login ${HARBOR_URL} -u ${USER} -p ${PASS}"
|
||||||
sh "docker push ${FULL_IMAGE_PATH}"
|
sh "docker push ${FULL_IMAGE_PATH}"
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// K8s Deploy
|
// K8s Deploy
|
||||||
|
container('kubectl') {
|
||||||
sh "sed 's|IMAGE_PATH_PLACEHOLDER|${FULL_IMAGE_PATH}|g' k8s-deployment.yaml > backend-k8s-applied.yaml"
|
sh "sed 's|IMAGE_PATH_PLACEHOLDER|${FULL_IMAGE_PATH}|g' k8s-deployment.yaml > backend-k8s-applied.yaml"
|
||||||
sh "kubectl apply -f backend-k8s-applied.yaml"
|
sh "kubectl apply -f backend-k8s-applied.yaml"
|
||||||
sh "kubectl rollout status deployment/${SERVICE_NAME}"
|
sh "kubectl rollout status deployment/${SERVICE_NAME}"
|
||||||
@@ -51,6 +55,7 @@ pipeline {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
stage('Frontend Service') {
|
stage('Frontend Service') {
|
||||||
environment {
|
environment {
|
||||||
@@ -61,24 +66,29 @@ pipeline {
|
|||||||
stages {
|
stages {
|
||||||
stage('Frontend: Test') {
|
stage('Frontend: Test') {
|
||||||
steps {
|
steps {
|
||||||
|
container('node') {
|
||||||
dir("${env.DIR}") {
|
dir("${env.DIR}") {
|
||||||
sh 'npm install'
|
sh 'npm install'
|
||||||
sh 'npm test || true'
|
sh 'npm test || true'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
stage('Frontend: Push & Deploy') {
|
stage('Frontend: Push & Deploy') {
|
||||||
steps {
|
steps {
|
||||||
dir("${env.DIR}") {
|
dir("${env.DIR}") {
|
||||||
script {
|
script {
|
||||||
// Build & Push
|
// Build & Push
|
||||||
|
container('docker') {
|
||||||
sh "docker build -t ${FULL_IMAGE_PATH} ."
|
sh "docker build -t ${FULL_IMAGE_PATH} ."
|
||||||
withCredentials([usernamePassword(credentialsId: "${HARBOR_CREDS}", usernameVariable: 'USER', passwordVariable: 'PASS')]) {
|
withCredentials([usernamePassword(credentialsId: "${HARBOR_CREDS}", usernameVariable: 'USER', passwordVariable: 'PASS')]) {
|
||||||
sh "docker login ${HARBOR_URL} -u ${USER} -p ${PASS}"
|
sh "docker login ${HARBOR_URL} -u ${USER} -p ${PASS}"
|
||||||
sh "docker push ${FULL_IMAGE_PATH}"
|
sh "docker push ${FULL_IMAGE_PATH}"
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// K8s Deploy
|
// K8s Deploy
|
||||||
|
container('kubectl') {
|
||||||
sh "sed 's|IMAGE_PATH_PLACEHOLDER|${FULL_IMAGE_PATH}|g' k8s-deployment.yaml > frontend-k8s-applied.yaml"
|
sh "sed 's|IMAGE_PATH_PLACEHOLDER|${FULL_IMAGE_PATH}|g' k8s-deployment.yaml > frontend-k8s-applied.yaml"
|
||||||
sh "kubectl apply -f frontend-k8s-applied.yaml"
|
sh "kubectl apply -f frontend-k8s-applied.yaml"
|
||||||
sh "kubectl rollout status deployment/${SERVICE_NAME}"
|
sh "kubectl rollout status deployment/${SERVICE_NAME}"
|
||||||
@@ -91,11 +101,13 @@ pipeline {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
post {
|
post {
|
||||||
always {
|
always {
|
||||||
|
container('docker') {
|
||||||
sh "docker logout ${HARBOR_URL} || true"
|
sh "docker logout ${HARBOR_URL} || true"
|
||||||
// Cleanup temporary manifest files
|
}
|
||||||
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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user