-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile
94 lines (79 loc) · 2.42 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
pipeline {
agent {
node {
label 'master'
}
}
stages {
// stage('PHPUnit Test') {
// steps {
// echo 'Running PHPUnit...'
// sh '/bin/phpunit ${WORKSPACE}/src'
// }
// }
stage("Create new tag") {
when {
expression {env.BRANCH_NAME == 'master'}
}
steps {
sshagent (credentials: ['25d16746-509b-4627-9398-9c13803222e7'])
{
script {
sh "git config --add remote.origin.fetch +refs/heads/master:refs/remotes/origin/master"
sh "git fetch"
def tag = sh(returnStdout: true, script: "git tag | tail -1").trim()
println tag
// def semVerLib = load 'SemVer.groovy'
def version = getTagversion(tag)
println version
sh """
git tag -a "v${version}" \
-m "Generated by: ${env.JENKINS_URL}" \
-m "Job: ${env.JOB_NAME}" \
-m "Build: ${env.BUILD_NUMBER}"
git push --tags
"""
}
}
}
}
}
}
def getTagversion (String oldtagVersion)
{
oldtagVersion = oldtagVersion.substring(1)
println oldtagVersion
def versionParts = oldtagVersion.tokenize('.')
println versionParts
major = versionParts[0].toInteger()
minor = versionParts[1].toInteger()
timetag = versionParts[2].toString()
this.month = timetag.substring(4,6).toInteger()
Calendar now = Calendar.getInstance();
currmonth = (now.get(Calendar.MONTH) +1)
Date date = new Date()
//println date.getTime()
//println date.format( 'yyyy-MM-ddHH:mm:ss.S' )
String newtimetag = date.format( 'yyyyMMdd-HHmm' ).toString()
//println strtimetag
//timetag= timetag.replaceAll(":","-")
if (currmonth==month)
{
version = major+ "." + minor + "." +newtimetag
}
else
{
if (month < 9)
{
minor = minor +1
version = major+ "." + minor + "." +newtimetag
}
else
{
major = this.major +1
minor = 0
version = major+ "." + minor + "." +newtimetag
}
}
return version
}