-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJenkinsfile
73 lines (65 loc) · 2.23 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
pipeline {
agent any
options {
buildDiscarder logRotator(artifactNumToKeepStr: '15', numToKeepStr: '15')
disableConcurrentBuilds()
}
environment {
GIT_HASH = GIT_COMMIT.take(7)
JDATE = new Date().format("yyDDDHHmm", TimeZone.getTimeZone('America/Denver'))
}
stages {
stage('Restore') {
steps {
powershell 'dotnet restore -s "https://api.nuget.org/v3/index.json"'
}
}
stage('Unit Test') {
steps {
powershell 'dotnet clean --configuration Debug'
powershell 'dotnet build --configuration Debug --no-restore'
powershell 'dotnet test --configuration Debug --no-build --filter TestCategory=Unit'
}
}
stage('Build') {
when { anyOf { branch 'prerelease*'; branch 'release*' } }
steps {
script {
def values = env.BRANCH_NAME.split('_')
env.BRANCH = values[0]
env.VERSION = values[1]
if (env.BRANCH == 'release') {
env.BRANCH_VERSION = "${env.VERSION}+${env.GIT_HASH}"
}
else {
env.BRANCH_VERSION = "${env.VERSION}-pre.${env.JDATE}+${env.GIT_HASH}"
}
}
powershell 'Write-Host "BRANCH_VERSION = $env:BRANCH_VERSION"'
powershell 'dotnet clean --configuration Release'
powershell 'dotnet build --configuration Release --no-restore -p:Version="$env:BRANCH_VERSION" -p:PublishRepositoryUrl=true'
}
}
stage('Package') {
when { anyOf { branch 'prerelease*'; branch 'release*' } }
steps {
powershell 'Remove-Item -Recurse -Force "$env:WORKSPACE\\nuget" -ErrorAction Ignore'
powershell 'dotnet pack --configuration Release --no-build --include-symbols -p:IncludeSymbols=true -p:SymbolPackageFormat=snupkg -p:PackageVersion="$env:BRANCH_VERSION" --output "$env:WORKSPACE\\nuget"'
}
}
stage('Publish') {
when { anyOf { branch 'prerelease*'; branch 'release*' } }
environment {
NUGET_API_KEY = credentials('nuget-api-key')
}
steps {
powershell 'dotnet nuget push "$env:WORKSPACE\\nuget\\*.nupkg" -k "$env:NUGET_API_KEY" -s https://api.nuget.org/v3/index.json'
}
}
}
post {
always {
cleanWs(cleanWhenSuccess: false)
}
}
}