-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathJenkinsfile
More file actions
34 lines (31 loc) · 1.21 KB
/
Jenkinsfile
File metadata and controls
34 lines (31 loc) · 1.21 KB
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
node() {
properties([
parameters([
string(name: 'docker_repo', defaultValue: 'YOUR-SERVICE-NAME', description: 'Docker Image Name'),
string(name: 'docker_server', defaultValue: 'localhost:5000', description: 'Docker Registry URL'),
])
])
stage('Checkout') {
cleanWs()
checkout scm
commit_hash = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim()
env.commit_id = sh(script: 'echo ' + env.docker_repo + '_' + commit_hash + '_' + env.BRANCH_NAME, returnStdout: true).trim()
echo "${env.commit_id}"
}
stage('docker-build') {
sh '''
# docker build -f <location-of-docker-file> -t <tag-of-docker-image> <context-for-docker-image>
docker build -f build/Dockerfile -t $docker_server/$docker_repo:$commit_id .
'''
}
stage('docker-push') {
sh '''
docker push $docker_server/$docker_repo:$commit_id
'''
}
stage('ArchiveArtifacts') {
sh("echo ${commit_id} > commit_id.txt")
archiveArtifacts 'commit_id.txt'
currentBuild.description = "${commit_id}"
}
}