-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
45 lines (45 loc) · 1.25 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
pipeline {
agent {
label 'master'
}
environment {
GO111MODULE = 'on'
CGO_ENABLED = '0'
ImageName = 'image-name'
Regist = 'registry.gitlab.com/repo'
Tag = "${GIT_BRANCH.replaceFirst('/', '-')}-${GIT_COMMIT.substring(0, Math.min(GIT_COMMIT.length(), 7))}"
}
stages {
stage('run-unit-test'){
steps {
sh "echo 'run unit test'"
}
}
stage('build-image') {
steps {
withDockerRegistry([ credentialsId:'DOCKER_CRED', url:'https://registry.gitlab.com' ]) {
sh "docker build -t ${Regist}/${ImageName}:${Tag} ."
}
}
}
stage('push-image'){
steps {
withDockerRegistry([ credentialsId:'DOCKER_CRED', url:'https://registry.gitlab.com' ]) {
sh "docker push ${Regist}/${ImageName}:${Tag}"
sh "docker rmi ${Regist}/${ImageName}:${Tag}"
}
}
}
stage('deploy'){
steps {
sh "echo 'deploy'"
}
}
}
post {
always{
deleteDir()
cleanWs externalDelete: 'rm -fr %s'
}
}
}