-
Notifications
You must be signed in to change notification settings - Fork 6
/
Jenkinsfile
204 lines (130 loc) · 6.5 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
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
pipeline {
agent none
stages {
stage('Build') {
agent {
dockerfile {
args '-u root:root'
}
}
steps {
echo sh(script: 'env|sort', returnStdout: true)
sh 'dotnet build ./Oragon.RabbitMQ.sln'
}
}
stage('Test') {
agent {
dockerfile {
// alwaysPull false
// image 'microsoft/dotnet:2.1-sdk'
// reuseNode false
args '-u root:root -v /var/run/docker.sock:/var/run/docker.sock'
}
}
steps {
withCredentials([usernamePassword(credentialsId: 'SonarQube', passwordVariable: 'SONARQUBE_KEY', usernameVariable: 'DUMMY' )])
{
script
{
def sonarParams = [
'/k:"Oragon.RabbitMQ"',
'/o:luizcarlosfaria',
'/d:sonar.token="$SONARQUBE_KEY"',
'/d:sonar.host.url="https://sonarcloud.io"',
'/d:sonar.cs.vscoveragexml.reportsPaths=/output-coverage/coverage.xml',
'/d:sonar.branch.name="$BRANCH_NAME"'
]
if (env.BRANCH_NAME == "master")
{
// reservado nesses nesses casos não é necessário
} else if (env.BRANCH_NAME == "develop")
{
sonarParams << '/d:sonar.branch.target=master'
} else if (env.BRANCH_NAME.startsWith('feature/')) {
sonarParams << '/d:sonar.branch.target=develop'
} else if (env.BRANCH_NAME.startsWith('hotfix/')) {
sonarParams << '/d:sonar.branch.target=master'
} else if (env.BRANCH_NAME.startsWith('release/')) {
sonarParams << '/d:sonar.branch.target=master'
} else {
// Não sabemos o que fazer
}
def sonarParamsText = sonarParams.join(" ")
// sonarcloud issue | https://community.sonarsource.com/t/could-not-find-ref-refs-heads-master-in-refs-heads-refs-remotes-upstream-or-refs-remotes-origin/37016/5
// git fetch origin master:master | git fetch origin develop:develop
sh """
git fetch origin master:master
git fetch origin develop:develop
export PATH="\$PATH:/root/.dotnet/tools"
dotnet sonarscanner begin ${sonarParamsText}
dotnet build --no-incremental ./Oragon.RabbitMQ.sln
dotnet-coverage collect "dotnet test" -f xml -o "/output-coverage/coverage.xml"
dotnet sonarscanner end /d:sonar.token="\$SONARQUBE_KEY"
"""
}
}
}
}
stage('Pack') {
agent {
dockerfile {
args '-u root:root'
}
}
when { buildingTag() }
steps {
script{
def projetcs = [
'Oragon.RabbitMQ',
'Oragon.RabbitMQ.Abstractions',
'Oragon.RabbitMQ.MinimalConsumer',
'Oragon.RabbitMQ.Serializer.NewtonsoftJson',
'Oragon.RabbitMQ.Serializer.SystemTextJson',
]
if (env.BRANCH_NAME.endsWith("-alpha")) {
for (int i = 0; i < projetcs.size(); ++i) {
sh "dotnet pack ./src/${projetcs[i]}/${projetcs[i]}.csproj --configuration Debug /p:PackageVersion=${BRANCH_NAME} --include-source --include-symbols --output ./output-packages"
}
} else if (env.BRANCH_NAME.endsWith("-beta")) {
for (int i = 0; i < projetcs.size(); ++i) {
sh "dotnet pack ./src/${projetcs[i]}/${projetcs[i]}.csproj --configuration Release /p:PackageVersion=${BRANCH_NAME} --output ./output-packages"
}
} else {
for (int i = 0; i < projetcs.size(); ++i) {
sh "dotnet pack ./src/${projetcs[i]}/${projetcs[i]}.csproj --configuration Release /p:PackageVersion=${BRANCH_NAME} --output ./output-packages"
}
}
}
}
}
stage('Publish') {
agent {
dockerfile {
args '-u root:root'
}
}
when { buildingTag() }
steps {
script {
def publishOnNuGet = ( env.BRANCH_NAME.endsWith("-alpha") == false );
withCredentials([usernamePassword(credentialsId: 'myget-oragon', passwordVariable: 'MYGET_KEY', usernameVariable: 'DUMMY' )]) {
sh 'for pkg in ./output-packages/*.nupkg ; do dotnet nuget push "$pkg" -k "$MYGET_KEY" -s https://www.myget.org/F/oragon/api/v3/index.json -ss https://www.myget.org/F/oragon/symbols/api/v2/package ; done'
}
if (publishOnNuGet) {
withCredentials([usernamePassword(credentialsId: 'nuget-luizcarlosfaria', passwordVariable: 'NUGET_KEY', usernameVariable: 'DUMMY')]) {
sh 'for pkg in ./output-packages/*.nupkg ; do dotnet nuget push "$pkg" -k "$NUGET_KEY" -s https://api.nuget.org/v3/index.json ; done'
}
}
}
}
}
}
/*post {
always {
node('master'){
sh '''
'''
}
}
}*/
}