-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathJenkinsfileRelease
142 lines (126 loc) · 5.99 KB
/
JenkinsfileRelease
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
parameters {
string(name: 'version', defaultValue: '19.10.0', description: 'version of gem')
string(name: 'deployKey', defaultValue: 'xxx', description: 'key')
string(name: 'apiUrl', defaultValue: 'https://api-qa.aspose.cloud', description: 'server url')
string(name: 'StartFromStage', defaultValue: '0', description: '0 based index of stage which will be started')
}
node('words-linux') {
try {
stage('0:Merge master to testPackage'){
checkout([$class: 'GitSCM', branches: [[name: '*/release']], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'LocalBranch', localBranch: "**"]], submoduleCfg: [], userRemoteConfigs: [[credentialsId: '361885ba-9425-4230-950e-0af201d90547', url: 'https://git.auckland.dynabic.com/words-cloud/words-cloud-ruby.git']]])
sh "git config user.email '[email protected]'"
sh "git config user.name 'jenkins'"
sh "git checkout --merge testPackage"
sh "git reset --hard origin/testPackage"
sh "git merge --no-ff --allow-unrelated-histories origin/release"
sh "git diff --name-status"
sh 'git commit -am "Merged release branch to testPackage" || exit 0'
withCredentials([usernamePassword(credentialsId: '361885ba-9425-4230-950e-0af201d90547', passwordVariable: 'gitPass', usernameVariable: 'gitUsername')]) {
sh "git push https://$gitUsername:[email protected]/words-cloud/words-cloud-ruby.git testPackage"
}
}
} finally {
cleanWs()
}
}
stage('1:wait for publishing'){
timeout(time:1, unit:'DAYS') {
input message:'Ready for publishing to rubygems?'
}
}
def testGemLocally()
{
try {
stage('2:checkout again'){
checkout([$class: 'GitSCM', branches: [[name: '*/testPackage']], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'LocalBranch', localBranch: "**"]], submoduleCfg: [], userRemoteConfigs: [[credentialsId: '361885ba-9425-4230-950e-0af201d90547', url: 'https://git.auckland.dynabic.com/words-cloud/words-cloud-ruby.git']]])
withCredentials([usernamePassword(credentialsId: '6839cbe8-39fa-40c0-86ce-90706f0bae5d', passwordVariable: 'ClientSecret', usernameVariable: 'ClientId')]) {
sh 'mkdir -p Settings'
sh 'echo "{\\"ClientId\\": \\"$ClientId\\",\\"ClientSecret\\": \\"$ClientSecret\\", \\"BaseUrl\\": \\"$apiUrl\\"}" > Settings/servercreds.json'
}
}
stage('3:build gem and test'){
docker.image('ruby:2.7').inside('-u root'){
stage('upload to rubygems'){
sh "gem build aspose_words_cloud.gemspec"
sh "gem install nokogiri -v 1.10.10"
sh "gem install ./aspose_words_cloud-${version}.gem"
}
stage('test gem locally'){
sh "mkdir testReports"
sh "gem install bundler -v 2.0.2 && bundle install"
try{
sh 'rake test'
} finally{
junit 'testReports/report/*.xml'
}
}
stage('clean-compiled'){
sh "rm -rf %s"
}
}
}
} finally {
cleanWs()
}
}
def publishGem()
{
try {
stage('4:checkout again'){
checkout([$class: 'GitSCM', branches: [[name: '*/release']], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'LocalBranch', localBranch: "**"]], submoduleCfg: [], userRemoteConfigs: [[credentialsId: '361885ba-9425-4230-950e-0af201d90547', url: 'https://git.auckland.dynabic.com/words-cloud/words-cloud-ruby.git']]])
}
stage('5:build gem publish'){
docker.image('ruby:2.7').inside('-u root'){
stage('upload to rubygems'){
sh "gem build aspose_words_cloud.gemspec"
sh "mkdir ~/.gem"
sh "touch ~/.gem/credentials"
withCredentials([string(credentialsId: 'bb609755-8dfb-4f45-819a-3dbfc85fc9fd', variable: 'deployKey')]) {
sh "echo ':rubygems_api_key: $deployKey' > ~/.gem/credentials"
}
sh "chmod 0600 ~/.gem/credentials"
sh "gem push aspose_words_cloud-${version}.gem"
}
stage('clean-compiled'){
sh "rm -rf %s"
}
}
}
stage('6:add version tag'){
checkout([$class: 'GitSCM', branches: [[name: '*/release']], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'LocalBranch', localBranch: "**"]], submoduleCfg: [], userRemoteConfigs: [[credentialsId: '361885ba-9425-4230-950e-0af201d90547', url: 'https://git.auckland.dynabic.com/words-cloud/words-cloud-ruby.git']]])
sh "git config user.email \"[email protected]\""
sh "git config user.name \"jenkins\""
sh "git tag -a ${version} -m 'version ${version}' | exit 0"
withCredentials([usernamePassword(credentialsId: '361885ba-9425-4230-950e-0af201d90547', passwordVariable: 'gitPass', usernameVariable: 'gitUsername')]) {
sh "git push https://$gitUsername:[email protected]/words-cloud/words-cloud-ruby.git ${version}"
}
}
} finally {
cleanWs()
}
}
node('words-linux') {
stage('Merge master to release'){
checkout([$class: 'GitSCM', branches: [[name: '*/release']], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'LocalBranch', localBranch: "**"]], submoduleCfg: [], userRemoteConfigs: [[credentialsId: '361885ba-9425-4230-950e-0af201d90547', url: 'https://git.auckland.dynabic.com/words-cloud/words-cloud-ruby.git']]])
sh "git config user.email '[email protected]'"
sh "git config user.name 'jenkins'"
sh "git checkout --merge release"
sh "git reset --hard origin/release"
sh "git merge --no-ff --allow-unrelated-histories origin/master"
sh "git diff --name-status"
sh 'git commit -am "Merged master branch to release" || exit 0'
withCredentials([usernamePassword(credentialsId: '361885ba-9425-4230-950e-0af201d90547', passwordVariable: 'gitPass', usernameVariable: 'gitUsername')]) {
sh "git push https://$gitUsername:[email protected]/words-cloud/words-cloud-ruby.git release"
}
}
try {
testGemLocally()
} finally {
cleanWs()
}
try {
publishGem()
} finally {
cleanWs()
}
}