edit jenkins
This commit is contained in:
parent
a48212862c
commit
7e2c4dd62f
|
|
@ -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 {
|
pipeline {
|
||||||
agent any // Runs on an Ubuntu-based Jenkins agent
|
agent any // Runs on an Ubuntu-based Jenkins agent
|
||||||
|
|
||||||
|
|
@ -12,54 +37,66 @@ pipeline {
|
||||||
stages {
|
stages {
|
||||||
stage('Checkout Code') {
|
stage('Checkout Code') {
|
||||||
steps {
|
steps {
|
||||||
git branch: 'dev', url: 'https://git.winteraccess.id/winter-access/backend_nam.git', credentialsId: "${CREDENTIALS_ID}"
|
container('jnlp') {
|
||||||
|
git branch: 'dev', url: 'https://git.winteraccess.id/winter-access/backend_nam.git', credentialsId: "${CREDENTIALS_ID}"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Get Short SHA') {
|
stage('Get Short SHA') {
|
||||||
steps {
|
steps {
|
||||||
script {
|
container('jnlp') {
|
||||||
env.SHORT_SHA = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim()
|
script {
|
||||||
|
env.SHORT_SHA = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Login to Registry') {
|
stage('Login to Registry') {
|
||||||
steps {
|
steps {
|
||||||
script {
|
container('docker') {
|
||||||
withCredentials([usernamePassword(credentialsId: "${DOCKERUSRPASS}", usernameVariable: 'REGISTRY_USER', passwordVariable: 'REGISTRY_TOKEN')]) {
|
script {
|
||||||
sh """
|
withCredentials([usernamePassword(credentialsId: "${DOCKERUSRPASS}", usernameVariable: 'REGISTRY_USER', passwordVariable: 'REGISTRY_TOKEN')]) {
|
||||||
echo "$REGISTRY_TOKEN" | docker login "$REGISTRY_URL" --username ${REGISTRY_USER} --password-stdin
|
sh """
|
||||||
"""
|
echo "$REGISTRY_TOKEN" | docker login "$REGISTRY_URL" --username ${REGISTRY_USER} --password-stdin
|
||||||
|
"""
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Build and Push Docker Image') {
|
stage('Build and Push Docker Image') {
|
||||||
steps {
|
steps {
|
||||||
container('kaniko') {
|
container('docker') {
|
||||||
script {
|
script {
|
||||||
def imageTag = "dev-${env.SHORT_SHA}"
|
def imageTag = "dev-${env.SHORT_SHA}"
|
||||||
sh """
|
sh """
|
||||||
/kaniko/executor --context=dir://. \
|
docker build -t ${REGISTRY_URL}/${IMAGE_NAME}:${imageTag} \
|
||||||
--dockerfile=deploy/docker/Dockerfile \
|
-t ${REGISTRY_URL}/${IMAGE_NAME}:dev \
|
||||||
--destination=${REGISTRY_URL}/${IMAGE_NAME}:${imageTag} \
|
-t ${REGISTRY_URL}/${IMAGE_NAME}:latest \
|
||||||
--destination=${REGISTRY_URL}/${IMAGE_NAME}:dev \
|
-f deploy/docker/Dockerfile .
|
||||||
--destination=${REGISTRY_URL}/${IMAGE_NAME}:latest
|
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') {
|
stage('Deploy to Kubernetes') {
|
||||||
steps {
|
steps {
|
||||||
script {
|
container('jnlp') {
|
||||||
withCredentials([string(credentialsId: "${KUBE_CONFIG_ID}", variable: 'KUBE_CONFIG')]) {
|
script {
|
||||||
writeFile file: 'kubeconfig', text: KUBE_CONFIG
|
withCredentials([string(credentialsId: "${KUBE_CONFIG_ID}", variable: 'KUBE_CONFIG')]) {
|
||||||
sh """
|
writeFile file: 'kubeconfig', text: KUBE_CONFIG
|
||||||
kubectl apply -f deploy/kubernetes/dev.yaml --kubeconfig=kubeconfig
|
sh """
|
||||||
kubectl set image deployment/backend backend=${REGISTRY_URL}/${IMAGE_NAME}:dev-${env.SHORT_SHA} -n nam-backend-dev --kubeconfig=kubeconfig
|
kubectl apply -f deploy/kubernetes/dev.yaml --kubeconfig=kubeconfig
|
||||||
"""
|
kubectl set image deployment/backend backend=${REGISTRY_URL}/${IMAGE_NAME}:dev-${env.SHORT_SHA} -n nam-backend-dev --kubeconfig=kubeconfig
|
||||||
|
"""
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue