-
Notifications
You must be signed in to change notification settings - Fork 15
/
jenkinsfile
54 lines (54 loc) · 1.4 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
pipeline {
agent
node {
label 'generic'
}
options {
buildDiscarder(logRotator(numToKeepStr: '5'))
}
environment
{
VERSION = 'latest'
PROJECT = 'shelleg/gitbook'
IMAGE = "${PROJECT}/${VERSION}:latest"
}
stages {
stage('Build preparations')
{
steps
{
script
{
// calculate GIT lastest commit short-hash
gitCommitHash = sh(returnStdout: true, script: 'git rev-parse HEAD').trim()
shortCommitHash = gitCommitHash.take(7)
// calculate a sample version tag
VERSION = shortCommitHash
// set the build display name
currentBuild.displayName = "#${BUILD_ID}-${VERSION}"
IMAGE = "$PROJECT:$VERSION"
IMAGE_LATEST = "$PROJECT:latest"
}
}
}
stage('Build') {
steps {
docker.build("$IMAGE")
docker.build("$IMAGE_LATEST")
}
}
stage('Publish') {
when {
branch 'master'
}
steps {
withDockerRegistry([ credentialsId: "dockerHub", url: "" ]) {
// version eq latest git tag
docker.image(IMAGE).push()
// override the latest tag
docker.image(IMAGE_LATEST).push()
}
}
}
}
}