-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
61 lines (61 loc) · 2.63 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
59
60
61
def PROJECT_NAME = "api-start"
def gitUrl = "https://github.com/oscka/${PROJECT_NAME}"
def imgRegistry = "https://registry.hub.docker.com"
def gitOpsUrl = "https://github.com/oscka/gitops-openmsa"
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: "binam33-git" ]], //credential 이름이 jenkins에 등록된 이름과 동일해야 함
branches: [[name: "refs/tags/${TAG}"]]],
poll: false
script{
docker.withRegistry("${imgRegistry}","imageRegistry-credential"){ //credential 이름이 jenkins에 등록된 이름과 동일해야 함, jenkins에 docker deploy 권한 필요
sh "pwd"
sh "chmod u+x ./gradlew"
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')
gitUsernamePassword(credentialsId: 'binam33-git', gitToolName: 'Default')
]) {
sh """
git clone ${gitOpsUrl}
cd ./gitops-openmsa/${PROJECT_NAME}/rolling-update
kustomize edit set image oscka/${PROJECT_NAME}:${TAG}
# 로컬외에는 주석 제거한다
git config --global user.email "[email protected]"
git config --global user.name "demo"
git add .
git commit -am 'update image tag ${TAG}'
git remote set-url --push origin ${gitOpsUrl}
git push origin ${opsBranch}
"""
}
print "git push finished !!!"
}
}
}
}