forked from wardviaene/docker-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
75 lines (62 loc) · 2.66 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
pipeline {
agent any
stages {
stage('build ') {
steps {
nodejs('nodejs') {
sh 'npm install'
}
}
}
stage('test') {
steps {
nodejs('nodejs') {
sh 'npm test'
}
}
}
stage('notifier'){
steps {
slackSend (color: '#00FF00', message: "SUCCESSFUL: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})")
sh label: '', script: ''' printenv
echo "Git commit: $GIT_COMMIT"
echo "Git branch: $GIT_BRANCH"
echo "Git local branch: $GIT_LOCAL_BRANCH"
echo "Git previous commit:$GIT_PREVIOUS_COMMIT"
echo "Git previous successful commit: $GIT_PREVIOUS_SUCCESSFUL_COMMIT"
echo "Git url: $GIT_URL"
echo "Git url n: $GIT_URL_N"
echo "Git author name: $GIT_AUTHOR_NAME"
echo "Git commiter email: $GIT_COMMITTER_EMAIL"'''
//def gitData=getCommitsRange()
script {
//def currentCommitHash = currentBuild.getAction(hudson.plugins.git.util.BuildData.class).lastBuiltRevision.sha1String
//def previousCommitHash = currentBuild.previousBuild(hudson.plugins.git.util.BuildData.class).lastBuiltRevision.sha1String
//print "currentCommitHash:${currentCommitHash}"
//print "previousCommitHash:${previousCommitHash}"
print "Project Name: ${env.JOB_NAME}, Build Number: ${env.BUILD_NUMBER}"
def commitsRange = getCommitsRange(env.JOB_NAME, env.BUILD_NUMBER.toInteger())
print commitsRange
}
}
}
}
}
//Helper Methods
def getBuildInstanceFor(projectName, buildNumber) {
return Jenkins.getInstance().getItemByFullName(projectName).getBuildByNumber(buildNumber)
}
def getCommitsRange(projectName, buildNumber) {
def currentBuild = getBuildInstanceFor(projectName, buildNumber)
def previousBuild = getBuildInstanceFor(projectName, buildNumber - 1)
def currentCommitHash = currentBuild.getAction(hudson.plugins.git.util.BuildData.class).lastBuiltRevision.sha1String
def previousCommitHash = previousBuild.getAction(hudson.plugins.git.util.BuildData.class).lastBuiltRevision.sha1String
return [
projectName: projectName,
current: currentCommitHash,
previous: previousCommitHash
]
}
def getGitInfo() {
def changeLogSets = currentBuild.changeSets
}