-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathJenkinsfile_Ext
126 lines (111 loc) · 7.93 KB
/
Jenkinsfile_Ext
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
pipeline{
// Consider any agent
// agent any
// Consider only agent
agent {
label 'agent2'
}
// Exclude an agent
// agent {
// label '!agent1'
// }
environment{
PROJECT_NAME = "Volt MX Document External Server"
}
options{
buildDiscarder(logRotator(numToKeepStr: "10"))
}
stages{
stage('Build'){
steps{
echo "volt-mx-doc-opnsrc - repository is clonned from git scm to local"
echo "workspace used in this job is: ${env.WORKSPACE}"
sh "echo present working directory"
sh "pwd"
sh "git status"
//-------
// note: cherry-pick PRs from 'master' branch to 'rel/HPHX' branch created from "release" branch , and publish/push changes from this branch "rel/HPHX" to remote.
// note: before above step, PRs should be ready in master branch
// note: for testing, create a branch "rel1" in master branch, do the changes, cherrypick commit from "rel1" to "rel/HPHX" branch created in release.
// sh "git checkout -b rel/HPHX"
//-------
// ------- fetch branches from remote -------
//-----
echo "fetching branches from remote to automation server.."
//sh "git fetch origin ${params.Auto_Branch}:${params.Auto_Branch}"
sh "git checkout ${params.Auto_Branch}" //rel/A1
sh "git fetch origin ${params.Auto_Branch}"
sh "git pull origin ${params.Auto_Branch}"
echo "checkout to ${params.Release_Branch} branch and merge changes from ${params.Release_Branch} branch"
sh "git checkout ${params.Release_Branch}"
sh "git fetch origin ${params.Release_Branch}"
sh "git pull origin ${params.Release_Branch}"
sh "git merge ${params.Auto_Branch}"
sh "git pull origin ${params.Release_Branch}"
sh "git push origin ${params.Release_Branch}"
sh "git status"
sh "git fetch origin ${params.Release_Branch}"
sh "git pull origin ${params.Release_Branch}"
echo "Building Volt MX Docs Site..."
// 9.2 - buildDocs.sh , 9.5 - buildDocs_95.sh
sh "sh ${params.Doc_Version}"
echo "Build completed Successfully..."
echo "Staging and Committing the Changes..."
sh "git add ."
sh "git commit --allow-empty -am 'Release Build'"
sh "git pull origin ${params.Release_Branch}"
sh "git push origin ${params.Release_Branch}"
// ----------------------------------------------------//
// -----
sh "git status"
sh "git checkout -b ${params.New_Branch}"
sh "git push volt-mx-docs ${params.New_Branch}"
sh "gh pr create -t '${params.Commit_Summary}' -b '${params.Commit_Description}'"
sh "gh pr status"
sh "gh pr merge --merge"
sh "git checkout ${params.Release_Branch}"
sh "git status"
sh "git branch -D ${params.New_Branch}"
sh "git status"
sh "git branch -D ${params.Auto_Branch}"
// -----
}
}
}
post {
success{
echo "Build result is ${currentBuild.currentResult} !"
}
failure{
echo "Build result is ${currentBuild.currentResult}. Please check the console logs to re-run the build"
}
always{
echo " ----------- Build Details ----------- "
echo "Build Number: ${env.BUILD_NUMBER}"
echo "Build Result: ${currentBuild.currentResult}"
script{
def author_name = sh script: "git show -s --pretty=\"%an\" ${GIT_COMMIT}", returnStdout: true
def author_email_id = sh script: "git show -s --pretty=\"%ae\" ${GIT_COMMIT}", returnStdout: true
def commit_hash = sh script: "git show -s --pretty=\"%h\" ${GIT_COMMIT}", returnStdout: true
def commit_date = sh script: "git show -s --pretty=\"%ar\" ${GIT_COMMIT}", returnStdout: true
def commit_message = sh script: "git show -s --pretty=\"%s\" ${GIT_COMMIT}", returnStdout: true
def commit_message2 = sh script: "git show -s --pretty=\"%b\" ${GIT_COMMIT}", returnStdout: true
println("${author_email_id}")
sh "echo 'Last 5 commit/change history'"
//def n1 = sh script: "git show -s --pretty=format:'Author_Name: %an, Author_Email_Id: %ae, Committed_Time: %ar, Changes: %s, Change_Description: %b, Commit_Hash_Id: %h .' ${GIT_COMMIT} -5 ", returnStdout: true
def n1 = sh script: "git show -s --pretty=format:'Author_Name: %an, Author_Email_Id: %ae, Committed_Time: %ar, Changes: %s, Commit_Hash_Id: %h.' ${GIT_COMMIT} -5 ", returnStdout: true
println("${n1}")
println("Datatype of n1 is :")
println(n1.getClass().getName())
def (h1,h2,h3,h4,h5) = "${n1}".tokenize('\n')
println("Commit History 1: ${h1}")
println("Commit History 2: ${h2}")
println("Commit History 3: ${h3}")
println("Commit History 4: ${h4}")
println("Commit History 5: ${h5}")
//emailext attachLog: true, compressLog:true, body:"<p>***********************************************************************************</p><h2>${env.PROJECT_NAME} - Build Status: </h2><h3><u>Present Build Updates:</u></h3><table><tr><th>Build Number: </th><td><code>${env.BUILD_NUMBER}</code></td></tr><tr><th>Build Status: </th><td><code>${currentBuild.currentResult}</code></td></tr><tr><th>Build Duration: </th><td><code>${currentBuild.durationString}</code></td></tr></table><h3><u>Last 5 ChangeSets/History:</u></h3><table><tr><th>Commit History-1:</th><td><code>${h1}</code></td></tr><tr><th>Commit History-2:</th><td><code>${h2}</code></td></tr><tr><th>Commit History-3:</th><td><code>${h3}</code></td></tr><tr><th>Commit History-4:</th><td><code>${h4}</code></td></tr><tr><th>Commit History-5:</th><td><code>${h5}</code></td></tr></table><p>Please check the attached build logs and output to view the results in detail.</p><p>Verify your changes published externally from this base URL: <br>https://opensource.hcltechsw.com/volt-mx-docs/docs/documentation/ .</p><p>***********************************************************************************</p>", replyTo: '[email protected]', subject: "${env.PROJECT_NAME} - Build # ${env.BUILD_NUMBER} - ${currentBuild.currentResult}!", to: '[email protected], [email protected], [email protected], [email protected], [email protected], [email protected]'
emailext attachLog: true, compressLog:true, body:"<p>***********************************************************************************</p><h2>${env.PROJECT_NAME} - Build Status: </h2><h3><u>Present Build Updates:</u></h3><table><tr><th>Build Number: </th><td><code>${env.BUILD_NUMBER}</code></td></tr><tr><th>Build Status: </th><td><code>${currentBuild.currentResult}</code></td></tr><tr><th>Build Duration: </th><td><code>${currentBuild.durationString}</code></td></tr></table><h3><u>Last 5 ChangeSets/History:</u></h3><table><tr><th>Commit History-1:</th><td><code>${h1}</code></td></tr><tr><th>Commit History-2:</th><td><code>${h2}</code></td></tr><tr><th>Commit History-3:</th><td><code>${h3}</code></td></tr><tr><th>Commit History-4:</th><td><code>${h4}</code></td></tr><tr><th>Commit History-5:</th><td><code>${h5}</code></td></tr></table><p>Please check the attached build logs and output to view the results in detail.</p><p>Verify your changes published externally from this base URL: <br>https://opensource.hcltechsw.com/volt-mx-docs/docs/documentation/ .</p><p>***********************************************************************************</p>", replyTo: '[email protected]', subject: "${env.PROJECT_NAME} - Build # ${env.BUILD_NUMBER} - ${currentBuild.currentResult}!", to: '[email protected]'
}
}
}
}