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,20 +37,25 @@ pipeline {
|
||||||
stages {
|
stages {
|
||||||
stage('Checkout Code') {
|
stage('Checkout Code') {
|
||||||
steps {
|
steps {
|
||||||
|
container('jnlp') {
|
||||||
git branch: 'dev', url: 'https://git.winteraccess.id/winter-access/backend_nam.git', credentialsId: "${CREDENTIALS_ID}"
|
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 {
|
||||||
|
container('jnlp') {
|
||||||
script {
|
script {
|
||||||
env.SHORT_SHA = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim()
|
env.SHORT_SHA = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
stage('Login to Registry') {
|
stage('Login to Registry') {
|
||||||
steps {
|
steps {
|
||||||
|
container('docker') {
|
||||||
script {
|
script {
|
||||||
withCredentials([usernamePassword(credentialsId: "${DOCKERUSRPASS}", usernameVariable: 'REGISTRY_USER', passwordVariable: 'REGISTRY_TOKEN')]) {
|
withCredentials([usernamePassword(credentialsId: "${DOCKERUSRPASS}", usernameVariable: 'REGISTRY_USER', passwordVariable: 'REGISTRY_TOKEN')]) {
|
||||||
sh """
|
sh """
|
||||||
|
|
@ -35,24 +65,30 @@ pipeline {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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 {
|
||||||
|
container('jnlp') {
|
||||||
script {
|
script {
|
||||||
withCredentials([string(credentialsId: "${KUBE_CONFIG_ID}", variable: 'KUBE_CONFIG')]) {
|
withCredentials([string(credentialsId: "${KUBE_CONFIG_ID}", variable: 'KUBE_CONFIG')]) {
|
||||||
writeFile file: 'kubeconfig', text: KUBE_CONFIG
|
writeFile file: 'kubeconfig', text: KUBE_CONFIG
|
||||||
|
|
@ -65,6 +101,7 @@ pipeline {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
post {
|
post {
|
||||||
always {
|
always {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue