jenkinsfile
Some checks failed
eCommerce-backend/pipeline/head There was a failure building this commit

This commit is contained in:
2026-02-20 15:25:09 +00:00
parent 4d5c71942c
commit f66f7c8d10

20
Jenkinsfile vendored
View File

@@ -7,6 +7,8 @@ pipeline {
IMAGE_NAME = "ecommerce-backend" IMAGE_NAME = "ecommerce-backend"
IMAGE_TAG = "${REGISTRY}/library/${IMAGE_NAME}:${env.BRANCH_NAME}-${env.BUILD_NUMBER}" IMAGE_TAG = "${REGISTRY}/library/${IMAGE_NAME}:${env.BRANCH_NAME}-${env.BUILD_NUMBER}"
NAMESPACE = "ecommerce" NAMESPACE = "ecommerce"
// Pointing to the internal nerdctl/buildkit socket
BUILDKIT_HOST = "unix:///run/buildkit/buildkitd.sock"
} }
stages { stages {
@@ -19,7 +21,7 @@ pipeline {
stage('Build Image') { stage('Build Image') {
steps { steps {
script { script {
// Stripped down to the bare minimum. No flags, just the tag. // nerdctl needs to know which containerd socket to use
sh "docker build -t ${IMAGE_TAG} ." sh "docker build -t ${IMAGE_TAG} ."
} }
} }
@@ -39,7 +41,8 @@ pipeline {
stage('Inject to K8s Cache') { stage('Inject to K8s Cache') {
steps { steps {
script { script {
// Export from Docker and Import to Containerd k8s namespace // Since your agent is already using the containerd socket,
// the image might already be in the cache, but this ensures it.
sh "docker save ${IMAGE_TAG} | sudo ctr -n k8s.io images import -" sh "docker save ${IMAGE_TAG} | sudo ctr -n k8s.io images import -"
} }
} }
@@ -49,22 +52,11 @@ pipeline {
steps { steps {
script { script {
withCredentials([file(credentialsId: 'k8s-config', variable: 'KUBECONFIG')]) { withCredentials([file(credentialsId: 'k8s-config', variable: 'KUBECONFIG')]) {
// Update the deployment image and set pull policy to Never sh "kubectl --kubeconfig=${KUBECONFIG} patch deployment ${APP_NAME} -n ${NAMESPACE} --patch '{\"spec\": {\"template\": {\"spec\": {\"containers\": [{\"name\": \"${APP_NAME}\", \"image\": \"${IMAGE_TAG}\", \"imagePullPolicy\": \"Never\"}]}}}}'"
sh """
kubectl --kubeconfig=${KUBECONFIG} patch deployment ${APP_NAME} -n ${NAMESPACE} --patch \
'{"spec": {"template": {"spec": {"containers": [{"name": "${APP_NAME}", "image": "${IMAGE_TAG}", "imagePullPolicy": "Never"}]}}}}'
"""
sh "kubectl --kubeconfig=${KUBECONFIG} rollout status deployment/${APP_NAME} -n ${NAMESPACE}" sh "kubectl --kubeconfig=${KUBECONFIG} rollout status deployment/${APP_NAME} -n ${NAMESPACE}"
} }
} }
} }
} }
} }
post {
always {
// Use || true so the build doesn't fail if the image was never created
sh "docker rmi ${IMAGE_TAG} || true"
}
}
} }