forked from caicloud/helm-registry
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
106 lines (100 loc) · 3.82 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
def IMAGE_TAG = "caicloud/helm-registry:${params.imageTag}"
podTemplate(
cloud: 'dev-cluster',
namespace: 'kube-system',
name: 'helm-registry',
label: 'helm-registry',
idleMinutes: 1440,
containers: [
containerTemplate(
name: 'jnlp',
image: "cargo.caicloud.io/circle/jnlp:2.62",
alwaysPullImage: true,
command: '',
args: '${computer.jnlpmac} ${computer.name}',
),
containerTemplate(
name: 'dind',
image: "cargo.caicloud.io/caicloud/docker:17.03-dind",
alwaysPullImage: true,
ttyEnabled: true,
command: '',
args: '--host=unix:///home/jenkins/docker.sock',
privileged: true,
),
containerTemplate(
name: 'golang',
image: "cargo.caicloud.io/caicloud/golang-docker:1.8.1-17.05",
alwaysPullImage: true,
ttyEnabled: true,
command: '',
args: '',
envVars: [
containerEnvVar(key: 'DOCKER_HOST', value: 'unix:///home/jenkins/docker.sock'),
containerEnvVar(key: 'DOCKER_API_VERSION', value: '1.26'),
containerEnvVar(key: 'WORKDIR', value: '/go/src/github.com/caicloud/helm-registry')
],
),
]
) {
node('helm-registry') {
stage('Checkout') {
checkout scm
}
container('golang') {
ansiColor('xterm') {
stage("Complie") {
sh('''
set -e
mkdir -p $(dirname ${WORKDIR})
rm -rf ${WORKDIR}
ln -sf $(pwd) ${WORKDIR}
cd ${WORKDIR}
make registry
''')
}
stage('Run e2e test') {
if (!params.integration) {
echo "skip integration"
return
}
sh('''
set -e
cd ${WORKDIR}
make test
''')
}
}
stage("Build image and publish") {
if (!params.publish) {
echo "skip publish"
return
}
sh "docker build -t ${IMAGE_TAG} -f image/Dockerfile ."
docker.withRegistry("https://cargo.caicloudprivatetest.com", "cargo-private-admin") {
docker.image(IMAGE_TAG).push()
}
if (params.autoGitTag) {
echo "auto git tag: " + params.imageTag
withCredentials ([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'caicloud-bot', usernameVariable: 'GIT_USERNAME', passwordVariable: 'GIT_PASSWORD']]){
sh("git config --global user.email \"info@caicloud.io\"")
sh("git tag -a $imageTag -m \"$tagDescribe\"")
sh("git push https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/caicloud/helm-registry $imageTag")
}
}
}
}
stage('Deploy') {
if (!params.deploy) {
echo "skip deploy"
return
}
def kubeconfig = "kubeconfig-${params.deployTarget}"
withCredentials([[$class: 'FileBinding', credentialsId: kubeconfig, variable: 'SECRET_FILE']]) {
sh("""
kubectl --kubeconfig=$SECRET_FILE --namespace default get deploy helm-registry-v0.1.0 -o yaml | sed 's/helm-registry:.*\$/helm-registry:${params.imageTag}/' | kubectl --kubeconfig=$SECRET_FILE --namespace default replace -f -
""")
}
}
}
}