-
Notifications
You must be signed in to change notification settings - Fork 0
/
JenkinsfileRelease
137 lines (122 loc) · 5.1 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
parameters {
string(name: 'version', defaultValue: '18.7', description: 'version of gem')
string(name: 'deployKey', defaultValue: 'xxx', description: 'key')
string(name: 'testServerUrl', defaultValue: 'https://api.aspose.cloud', description: 'server url')
string(name: 'StartFromStage', defaultValue: '0', description: '0 based index of stage which will be started')
}
node('billing-qa-ubuntu-16.04.4') {
try {
stage('0:Merge master to testPackage'){
if (params.StartFromStage.toInteger() < 1) {
checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: '9d6c4dfa-042c-4ed1-81c7-9175179dddda', url: 'https://github.com/aspose-cad-cloud/aspose-cad-cloud-ruby.git/']]])
sh "git checkout --merge testPackage"
sh "git reset --hard origin/testPackage"
sh "git merge --no-ff --allow-unrelated-histories origin/master"
sh "git diff --name-status"
sh 'git commit -am "Merged master branch to testPackage" || exit 0'
withCredentials([usernamePassword(credentialsId: '9d6c4dfa-042c-4ed1-81c7-9175179dddda', passwordVariable: 'gitPass', usernameVariable: 'gitUsername')]) {
sh "git push https://cadCloud:$gitPass@github.com/aspose-cad-cloud/aspose-cad-cloud-ruby testPackage"
}
}
}
} finally {
cleanWs()
}
}
stage('1:wait for publishing'){
if (params.StartFromStage.toInteger() < 2) {
timeout(time:1, unit:'DAYS') {
input message:'Ready for publishing to rubygems?'
}
}
}
def testGemLocally()
{
try {
stage('2:checkout again'){
if (params.StartFromStage.toInteger() < 3) {
checkout([$class: 'GitSCM', branches: [[name: '*/testPackage']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: '9d6c4dfa-042c-4ed1-81c7-9175179dddda', url: 'https://github.com/aspose-cad-cloud/aspose-cad-cloud-ruby.git/']]])
withCredentials([usernamePassword(credentialsId: '6839cbe8-39fa-40c0-86ce-90706f0bae5d', passwordVariable: 'AppKey', usernameVariable: 'AppSid')]) {
sh 'mkdir -p Settings'
sh 'echo "{\\"AppSid\\": \\"$AppSid\\",\\"AppKey\\": \\"$AppKey\\", \\"BaseUrl\\": \\"${testServerUrl}\\"}" > Settings/servercreds.json'
}
}
}
stage('3:build gem and test'){
if (params.StartFromStage.toInteger() < 4) {
docker.image('ruby:2.4').inside('-u root'){
stage('upload to rubygems'){
sh "gem build aspose_cad_cloud.gemspec"
sh "gem install ./aspose_cad_cloud-${version}.gem"
}
stage('test gem locally'){
sh "mkdir testReports"
sh "gem install bundler && 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'){
if (params.StartFromStage.toInteger() < 5) {
checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: '9d6c4dfa-042c-4ed1-81c7-9175179dddda', url: 'https://github.com/aspose-cad-cloud/aspose-cad-cloud-ruby.git/']]])
}
}
stage('5:build gem publish'){
if (params.StartFromStage.toInteger() < 6) {
docker.image('ruby:2.4').inside('-u root'){
stage('upload to rubygems'){
sh "gem build aspose_cad_cloud.gemspec"
sh "mkdir ~/.gem"
sh "touch ~/.gem/credentials"
sh "echo ':rubygems_api_key: ${deployKey}' > ~/.gem/credentials"
sh "chmod 0600 ~/.gem/credentials"
sh "gem push aspose_cad_cloud-${version}.gem"
}
stage('clean-compiled'){
sh "rm -rf %s"
}
}
}
}
stage('6:add version tag'){
if (params.StartFromStage.toInteger() < 6) {
checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: '9d6c4dfa-042c-4ed1-81c7-9175179dddda', url: 'https://github.com/aspose-cad-cloud/aspose-cad-cloud-ruby.git/']]])
sh "git config user.email \"jenkins.aspose@gmail.com\""
sh "git config user.name \"jenkins\""
sh "git tag -a ${version} -m 'version ${version}' | exit 0"
withCredentials([usernamePassword(credentialsId: '9d6c4dfa-042c-4ed1-81c7-9175179dddda', passwordVariable: 'gitPass', usernameVariable: 'gitUsername')]) {
sh "git push https://cadCloud:$gitPass@github.com/aspose-cad-cloud/aspose-cad-cloud-ruby ${version}"
}
}
}
} finally {
cleanWs()
}
}
node('billing-qa-ubuntu-16.04.4') {
try {
testGemLocally()
} finally {
cleanWs()
}
try {
publishGem()
} finally {
cleanWs()
}
}