Files
eCommerce-backend/Jenkinsfile
subodh 2eede2b9dc
Some checks failed
eCommerce-backend/pipeline/head There was a failure building this commit
jenkinsfile
2026-02-20 15:58:41 +00:00

58 lines
2.3 KiB
Groovy

pipeline {
agent any
environment {
REGISTRY = "myharbor.local:80"
APP_NAME = "ecommerce-app"
IMAGE_NAME = "ecommerce-backend"
IMAGE_TAG = "${REGISTRY}/library/${IMAGE_NAME}:${env.BRANCH_NAME}-${env.BUILD_NUMBER}"
NAMESPACE = "ecommerce"
// Pointing nerdctl to the socket we found in your ls output
CONTAINERD_ADDR = "/run/containerd-pod/containerd.sock"
}
stages {
stage('Checkout') {
steps {
checkout scm
}
}
stage('Build Image') {
steps {
script {
// Use nerdctl directly with the explicit socket address
// we add --insecure-registry because harbor is on port 80
sh "nerdctl --address ${CONTAINERD_ADDR} build --insecure-registry -t ${IMAGE_TAG} ."
}
}
}
stage('Push to Harbor') {
steps {
script {
withCredentials([usernamePassword(credentialsId: 'harbor-creds', passwordVariable: 'PASS', usernameVariable: 'USER')]) {
sh "nerdctl --address ${CONTAINERD_ADDR} login ${REGISTRY} -u ${USER} -p ${PASS} --insecure-registry"
sh "nerdctl --address ${CONTAINERD_ADDR} push ${IMAGE_TAG} --insecure-registry"
}
}
}
}
stage('Deploy to K8s') {
steps {
script {
withCredentials([file(credentialsId: 'k8s-config', variable: 'KUBECONFIG')]) {
// Patch the deployment. Since nerdctl shares the containerd store,
// the image is already 'imported' effectively.
sh """
kubectl --kubeconfig=${KUBECONFIG} patch deployment ${APP_NAME} -n ${NAMESPACE} --patch \
'{"spec": {"template": {"spec": {"containers": [{"name": "${APP_NAME}", "image": "${IMAGE_TAG}", "imagePullPolicy": "IfNotPresent"}]}}}}'
"""
sh "kubectl --kubeconfig=${KUBECONFIG} rollout status deployment/${APP_NAME} -n ${NAMESPACE}"
}
}
}
}
}
}