-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathJenkinsfile
58 lines (58 loc) · 2.44 KB
/
Jenkinsfile
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
def PROJECT_NAME = "simple-api"
def gitUrl = "https://github.com/oscka/${PROJECT_NAME}.git"
def imgRegistry = "https://registry.hub.docker.com"
def gitOpsUrl = "https://github.com/oscka/simple-gitops.git"
def opsBranch = "main"
/////////////////////////////
pipeline {
environment {
PATH = "$PATH:/usr/local/bin/" //maven, skaffold, argocd,jq path
}
agent any
stages {
stage('Build') {
steps {
checkout scm: [
$class: "GitSCM",
userRemoteConfigs: [[url: "${gitUrl}",
credentialsId: "git-credential" ]], //credential 이름이 jenkins에 등록된 이름과 동일해야 함
branches: [[name: "refs/tags/${TAG}"]]],
poll: false
script{
docker.withRegistry("${imgRegistry}","imageRegistry-credential"){ //credential 이름이 jenkins에 등록된 이름과 동일해야 함, jenkins에 docker deploy 권한 필요
sh "skaffold build -p dev -t ${TAG}"
}
// mac local 일때만 사용 linux 환경에서는 docker.withRegistry 사용
// sh "skaffold build -p dev -t ${TAG}"
}
}
}
stage('workspace clear'){
steps {
cleanWs()
}
}
stage('GitOps update') {
steps{
print "======kustomization.yaml tag update====="
withCredentials([
gitUsernamePassword(credentialsId: 'git-credential', gitToolName: 'Default')
]) {
sh """
git clone ${gitOpsUrl}
cd ./simple-gitops/simple-api/rolling-update-no-istio
kustomize edit set image oscka/simple-api:${TAG}
# 로컬외에는 주석 제거한다
git config --global user.email "admin@demo.com"
git config --global user.name "admin"
git add .
git commit -am 'update image tag ${TAG}'
git remote set-url --push origin ${gitOpsUrl}
git push origin ${opsBranch}
"""
}
print "git push finished !!!"
}
}
}
}