From 2099d93e77978d002411f23f886551ad59f32633 Mon Sep 17 00:00:00 2001 From: gitea_admin Date: Mon, 16 Feb 2026 16:30:22 +0000 Subject: [PATCH] jenkinsfile --- Jenkinsfile | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..a03164a --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,82 @@ +pipeline { + agent { label 'static-agent' } + + environment { + HARBOR_REGISTRY = 'harbor.myriadcara.com' + HARBOR_PROJECT = 'library' + IMAGE_NAME = 'nodejs-app' + GITEA_HOST = 'gitea.myriadcara.com' + GITOPS_REPO = 'nodejs-app-gitops' + GITEA_USER = 'subodh' + } + + stages { + + stage('Checkout') { + steps { + checkout scm + } + } + + stage('Build Image') { + steps { + sh """ + docker build \ + -t ${HARBOR_REGISTRY}/${HARBOR_PROJECT}/${IMAGE_NAME}:${BUILD_NUMBER} \ + -t ${HARBOR_REGISTRY}/${HARBOR_PROJECT}/${IMAGE_NAME}:latest \ + . + """ + } + } + + stage('Push to Harbor') { + steps { + withCredentials([usernamePassword( + credentialsId: 'harbor-credentials', + usernameVariable: 'HARBOR_USER', + passwordVariable: 'HARBOR_PASS' + )]) { + sh """ + docker login ${HARBOR_REGISTRY} \ + -u ${HARBOR_USER} \ + -p ${HARBOR_PASS} + docker push ${HARBOR_REGISTRY}/${HARBOR_PROJECT}/${IMAGE_NAME}:${BUILD_NUMBER} + docker push ${HARBOR_REGISTRY}/${HARBOR_PROJECT}/${IMAGE_NAME}:latest + """ + } + } + } + + stage('Update GitOps Repo') { + steps { + withCredentials([usernamePassword( + credentialsId: 'gitea-credentials', + usernameVariable: 'GITEA_USER_CRED', + passwordVariable: 'GITEA_PASS' + )]) { + sh """ + rm -rf gitops-tmp + git clone https://${GITEA_USER_CRED}:${GITEA_PASS}@${GITEA_HOST}/${GITEA_USER}/${GITOPS_REPO}.git gitops-tmp + cd gitops-tmp && \ + sed -i 's|image: ${HARBOR_REGISTRY}/${HARBOR_PROJECT}/${IMAGE_NAME}:.*|image: ${HARBOR_REGISTRY}/${HARBOR_PROJECT}/${IMAGE_NAME}:${BUILD_NUMBER}|' k8s/deployment.yaml && \ + git config user.email "jenkins@ci.local" && \ + git config user.name "Jenkins" && \ + git add k8s/deployment.yaml && \ + git commit -m "Update image tag to build ${BUILD_NUMBER}" && \ + git push + rm -rf gitops-tmp + """ + } + } + } + } + + post { + success { + echo "Pipeline succeeded - ArgoCD will sync the new version" + } + failure { + echo "Pipeline failed" + } + } +} \ No newline at end of file