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

This commit is contained in:
2026-02-20 16:15:02 +00:00
parent 527d6dbbf2
commit aab74e950b

25
Jenkinsfile vendored
View File

@@ -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 &"
// 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"}]}}}}'
"""
}
}
}