diff --git a/Jenkinsfile b/Jenkinsfile index 5fe4e2b..73c10da 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,14 +1,13 @@ pipeline { - agent any + agent { + label 'build-agent' // This matches the label you configured + } environment { - // --- Shared Configuration --- - HARBOR_URL = 'harbor.example.com' + HARBOR_URL = 'harbor.myriadcara.com' // Fixed your URL HARBOR_PROJECT = 'my-todo-app' HARBOR_CREDS = 'harbor-credentials-id' K8S_CREDENTIALS_ID = 'k8s-kubeconfig' - - // Build Tag IMAGE_TAG = "${env.BUILD_ID}" } @@ -24,9 +23,11 @@ pipeline { stages { stage('Backend: Test') { steps { - dir("${env.DIR}") { - sh 'npm install' - sh 'npm test || true' + container('node') { + dir("${env.DIR}") { + sh 'npm install' + sh 'npm test || true' + } } } } @@ -35,16 +36,20 @@ pipeline { dir("${env.DIR}") { script { // Build & Push - sh "docker build -t ${FULL_IMAGE_PATH} ." - withCredentials([usernamePassword(credentialsId: "${HARBOR_CREDS}", usernameVariable: 'USER', passwordVariable: 'PASS')]) { - sh "docker login ${HARBOR_URL} -u ${USER} -p ${PASS}" - sh "docker push ${FULL_IMAGE_PATH}" + container('docker') { + sh "docker build -t ${FULL_IMAGE_PATH} ." + withCredentials([usernamePassword(credentialsId: "${HARBOR_CREDS}", usernameVariable: 'USER', passwordVariable: 'PASS')]) { + sh "docker login ${HARBOR_URL} -u ${USER} -p ${PASS}" + sh "docker push ${FULL_IMAGE_PATH}" + } } // K8s Deploy - 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 rollout status deployment/${SERVICE_NAME}" + container('kubectl') { + 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 rollout status deployment/${SERVICE_NAME}" + } } } } @@ -61,9 +66,11 @@ pipeline { stages { stage('Frontend: Test') { steps { - dir("${env.DIR}") { - sh 'npm install' - sh 'npm test || true' + container('node') { + dir("${env.DIR}") { + sh 'npm install' + sh 'npm test || true' + } } } } @@ -72,16 +79,20 @@ pipeline { dir("${env.DIR}") { script { // Build & Push - sh "docker build -t ${FULL_IMAGE_PATH} ." - withCredentials([usernamePassword(credentialsId: "${HARBOR_CREDS}", usernameVariable: 'USER', passwordVariable: 'PASS')]) { - sh "docker login ${HARBOR_URL} -u ${USER} -p ${PASS}" - sh "docker push ${FULL_IMAGE_PATH}" + container('docker') { + sh "docker build -t ${FULL_IMAGE_PATH} ." + withCredentials([usernamePassword(credentialsId: "${HARBOR_CREDS}", usernameVariable: 'USER', passwordVariable: 'PASS')]) { + sh "docker login ${HARBOR_URL} -u ${USER} -p ${PASS}" + sh "docker push ${FULL_IMAGE_PATH}" + } } // K8s Deploy - 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 rollout status deployment/${SERVICE_NAME}" + container('kubectl') { + 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 rollout status deployment/${SERVICE_NAME}" + } } } } @@ -94,9 +105,10 @@ pipeline { post { always { - sh "docker logout ${HARBOR_URL} || true" - // Cleanup temporary manifest files + container('docker') { + sh "docker logout ${HARBOR_URL} || true" + } sh "rm -f backend/backend-k8s-applied.yaml frontend/frontend-k8s-applied.yaml" } } -} +} \ No newline at end of file