edit jenkins

This commit is contained in:
areeqakbr 2025-02-25 09:36:24 +07:00
parent a48212862c
commit 7e2c4dd62f
1 changed files with 58 additions and 21 deletions

49
Jenkinsfile vendored
View File

@ -1,3 +1,28 @@
pipeline {
agent {
kubernetes {
yaml """
apiVersion: v1
kind: Pod
spec:
containers:
- name: jnlp
image: jenkins/inbound-agent:latest
- name: docker
image: docker:latest
command:
- cat
tty: true
volumeMounts:
- name: docker-sock
mountPath: /var/run/docker.sock
volumes:
- name: docker-sock
hostPath:
path: /var/run/docker.sock
"""
}
}
pipeline {
agent any // Runs on an Ubuntu-based Jenkins agent
@ -12,20 +37,25 @@ pipeline {
stages {
stage('Checkout Code') {
steps {
container('jnlp') {
git branch: 'dev', url: 'https://git.winteraccess.id/winter-access/backend_nam.git', credentialsId: "${CREDENTIALS_ID}"
}
}
}
stage('Get Short SHA') {
steps {
container('jnlp') {
script {
env.SHORT_SHA = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim()
}
}
}
}
stage('Login to Registry') {
steps {
container('docker') {
script {
withCredentials([usernamePassword(credentialsId: "${DOCKERUSRPASS}", usernameVariable: 'REGISTRY_USER', passwordVariable: 'REGISTRY_TOKEN')]) {
sh """
@ -35,24 +65,30 @@ pipeline {
}
}
}
}
stage('Build and Push Docker Image') {
steps {
container('kaniko') {
container('docker') {
script {
def imageTag = "dev-${env.SHORT_SHA}"
sh """
/kaniko/executor --context=dir://. \
--dockerfile=deploy/docker/Dockerfile \
--destination=${REGISTRY_URL}/${IMAGE_NAME}:${imageTag} \
--destination=${REGISTRY_URL}/${IMAGE_NAME}:dev \
--destination=${REGISTRY_URL}/${IMAGE_NAME}:latest
docker build -t ${REGISTRY_URL}/${IMAGE_NAME}:${imageTag} \
-t ${REGISTRY_URL}/${IMAGE_NAME}:dev \
-t ${REGISTRY_URL}/${IMAGE_NAME}:latest \
-f deploy/docker/Dockerfile .
docker push ${REGISTRY_URL}/${IMAGE_NAME}:${imageTag}
docker push ${REGISTRY_URL}/${IMAGE_NAME}:dev
docker push ${REGISTRY_URL}/${IMAGE_NAME}:latest
"""
}
}
}
}
stage('Deploy to Kubernetes') {
steps {
container('jnlp') {
script {
withCredentials([string(credentialsId: "${KUBE_CONFIG_ID}", variable: 'KUBE_CONFIG')]) {
writeFile file: 'kubeconfig', text: KUBE_CONFIG
@ -65,6 +101,7 @@ pipeline {
}
}
}
}
post {
always {