jenkinsfile
This commit is contained in:
82
Jenkinsfile
vendored
Normal file
82
Jenkinsfile
vendored
Normal file
@@ -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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user