This repository has been archived by the owner on Jun 19, 2019. It is now read-only.
forked from mendhak/docker-http-https-echo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
69 lines (59 loc) · 2.05 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
properties([
pipelineTriggers([
[$class: 'GitHubPushTrigger'], pollSCM('*/1 * * * *')
]),
disableConcurrentBuilds()
])
node {
ws("workspace/${env.JOB_NAME}/${env.BUILD_NUMBER}".replace('%2F', '_')) {
def PROJECT_NAME;
def ARTIFACT_VERSION;
def DOCKER_IMAGE_NAME;
def GIT_COMMIT_ID;
def GIT_BRANCH_NAME;
def GIT_REPOSITORY_URL;
def TIMESTAMP;
def DOCKER_IMAGE;
try {
stage("Checkout source") {
checkout scm
GIT_BRANCH_NAME = env.BRANCH_NAME.replaceAll("\\W", "_")
GIT_REPOSITORY_URL = env.GIT_URL
TIMESTAMP = new java.text.SimpleDateFormat("yyMMddHHmmss").format(new Date())
IS_MASTER_BRANCH = env.BRANCH_NAME == "master"
GIT_COMMIT_ID = sh(script: "git rev-parse HEAD", returnStdout: true).trim()
}
stage("Create version number") {
if (IS_MASTER_BRANCH) {
ARTIFACT_VERSION = "master.${env.BUILD_NUMBER}-${TIMESTAMP}".trim()
} else {
ARTIFACT_VERSION = "${GIT_BRANCH_NAME}.${env.BUILD_NUMBER}-${TIMESTAMP}".trim()
}
}
stage("Build") {
PROJECT_NAME = "http-https-echo";
DOCKER_IMAGE_NAME = PROJECT_NAME + ":" + ARTIFACT_VERSION;
DOCKER_IMAGE = docker.build(
DOCKER_IMAGE_NAME,
[
"-f Dockerfile",
"."
].join(" ")
)
}
stage("Publish version") {
// docker
docker.withRegistry(env.PRIVATE_DOCKER_REGISTRY_URL, 'DOCKER_REGISTRY_USER') {
DOCKER_IMAGE.push()
dockerFingerprintFrom dockerfile: 'Dockerfile', image: DOCKER_IMAGE_NAME
}
// jenkins
currentBuild.displayName = ARTIFACT_VERSION
}
} finally {
stage("Clean directory"){
deleteDir();
}
}
}
}