forked from rjhaikal/jenkins-argo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile-2
72 lines (71 loc) · 2.65 KB
/
Jenkinsfile-2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
pipeline {
environment {
IMAGE = "core.harbor.bignetlab.com/k8s-devops-harbor/k8s-debian-test"
REGISTRY = "core.harbor.bignetlab.com"
registryCredential = 'harbor'
HARBOR_CREDS = credentials('harbor')
dockerImage = ''
ARGOCD_SERVER="192.168.3.52"
APP_NAME="debian-test-k8s"
ARGOCD_CREDS = credentials('argocd-credentials')
}
agent any
stages {
stage('Prepare') {
steps {
checkout([$class: 'GitSCM',
branches: [[name: "origin/master"]],
doGenerateSubmoduleConfigurations: false,
submoduleCfg: [],
userRemoteConfigs: [[
url: 'https://github.com/rjhaikal/jenkins-argo.git']]
])
}
}
stage('Docker_Build') {
steps{
script {
dockerImage = docker.build IMAGE
}
}
}
stage('Docker_Login') {
steps {
sh '''
docker login $REGISTRY -u="${HARBOR_CREDS_USR}" -p="${HARBOR_CREDS_PSW}"
'''
}
}
stage('Docker_Push') {
steps{
script {
docker.withRegistry( 'https://core.harbor.bignetlab.com', registryCredential ) {
dockerImage.push("$BUILD_NUMBER")
dockerImage.push('latest')
}
}
}
}
stage('Scan Image') {
steps{
sh '''
trivy image --no-progress --exit-code 1 --severity HIGH,CRITICAL $IMAGE
'''
}
}
stage ('Deploy_K8S') {
steps {
sh '''
argocd login --insecure $ARGOCD_SERVER --username ${ARGOCD_CREDS_USR} --password ${ARGOCD_CREDS_PSW}
ARGOCD_SERVER=$ARGOCD_SERVER argocd app create $APP_NAME --project default --repo https://github.com/rjhaikal/jenkins-argo.git --path ./ --dest-namespace default --dest-server https://kubernetes.default.svc --upsert
IMAGE_DIGEST=$(docker image inspect $IMAGE:latest -f '{{join .RepoDigests ","}}')
## Customize image
ARGOCD_SERVER=$ARGOCD_SERVER argocd --grpc-web app set $APP_NAME --kustomize-image $IMAGE_DIGEST
# Deploy to ArgoCD
ARGOCD_SERVER=$ARGOCD_SERVER argocd --grpc-web app sync $APP_NAME --force
ARGOCD_SERVER=$ARGOCD_SERVER argocd --grpc-web app wait $APP_NAME --timeout 600
'''
}
}
}
}