From aab74e950b98ea13d7bcec75121477418c92824b Mon Sep 17 00:00:00 2001 From: subodh Date: Fri, 20 Feb 2026 16:15:02 +0000 Subject: [PATCH] jenkinsfile --- Jenkinsfile | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index b28599d..32b312f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -3,7 +3,7 @@ pipeline { environment { REGISTRY = "myharbor.local:80" - HARBOR_IP = "192.168.108.101" // Your Master Node IP + HARBOR_IP = "192.168.108.101" APP_NAME = "ecommerce-app" IMAGE_NAME = "ecommerce-backend" IMAGE_TAG = "${REGISTRY}/library/${IMAGE_NAME}:${env.BRANCH_NAME}-${env.BUILD_NUMBER}" @@ -14,18 +14,25 @@ pipeline { stages { stage('Network Setup') { steps { - // Manually inject the host entry for this build session - sh "echo '${HARBOR_IP} myharbor.local' | sudo tee -a /etc/hosts" + // No sudo needed, agent is running as root + sh "echo '${HARBOR_IP} myharbor.local' >> /etc/hosts" } } stage('Build Image') { steps { script { - // Start buildkitd if it died during pod rotation - sh "mkdir -p /run/buildkit && sudo chmod 777 /run/buildkit" - sh "nohup buildkitd --addr unix:///run/buildkit/buildkitd.sock > /tmp/buildkitd.log 2>&1 &" - sleep 10 + // Ensure directories exist for BuildKit + sh "mkdir -p /run/buildkit && chmod 777 /run/buildkit" + + // Start buildkitd in background if not running + sh """ + if ! pgrep buildkitd > /dev/null; then + echo "Starting buildkitd..." + nohup buildkitd --addr unix:///run/buildkit/buildkitd.sock > /tmp/buildkitd.log 2>&1 & + sleep 10 + fi + """ sh "nerdctl --address ${CONTAINERD_ADDR} build --insecure-registry -t ${IMAGE_TAG} ." } @@ -36,7 +43,6 @@ pipeline { steps { script { withCredentials([usernamePassword(credentialsId: 'harbor-creds', passwordVariable: 'PASS', usernameVariable: 'USER')]) { - // Using --password-stdin to remove the "insecure" warning sh "echo '${PASS}' | nerdctl --address ${CONTAINERD_ADDR} login ${REGISTRY} -u ${USER} --password-stdin --insecure-registry" sh "nerdctl --address ${CONTAINERD_ADDR} push ${IMAGE_TAG} --insecure-registry" } @@ -48,7 +54,10 @@ pipeline { steps { script { withCredentials([file(credentialsId: 'k8s-config', variable: 'KUBECONFIG')]) { - 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"}]}}}}' + """ } } }