-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile
68 lines (63 loc) · 2.27 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
pipeline {
agent { node { label 'docker' } }
environment {
VERSION_LIB = getVersionFromCsProj('Terradue.Tep/Terradue.Tep.csproj')
VERSION_TYPE = getTypeOfVersion(env.BRANCH_NAME)
CONFIGURATION = getConfiguration(env.BRANCH_NAME)
JENKINS_API_TOKEN = credentials('jenkins_api_token_repository')
}
stages {
stage('.Net Core') {
agent {
dockerfile {
additionalBuildArgs "-t dotnet/sdk-mono-tep:6.0 --build-arg JENKINS_API_TOKEN=${env.JENKINS_API_TOKEN}"
}
}
environment {
DOTNET_CLI_HOME = "/tmp/DOTNET_CLI_HOME"
}
stages {
stage("Build & Test") {
steps {
echo "Build .NET application"
sh "dotnet nuget add source https://repository.terradue.com/artifactory/api/nuget/nuget-release --name t2 --username jenkins --password ${env.JENKINS_API_TOKEN} --store-password-in-clear-text"
sh "dotnet restore ./"
sh "dotnet build -c ${env.CONFIGURATION} --no-restore ./"
sh "dotnet test -c ${env.CONFIGURATION} --no-build --no-restore ./"
}
}
stage('Publish NuGet') {
when{
branch pattern: "(release\\/[\\d.]+|master)", comparator: "REGEXP"
}
steps {
withCredentials([string(credentialsId: 'nuget_token', variable: 'NUGET_TOKEN')]) {
sh "dotnet pack Terradue.Tep/Terradue.Tep.csproj -c ${env.CONFIGURATION} -o publish"
sh "dotnet nuget push publish/*.nupkg --skip-duplicate -k $NUGET_TOKEN -s https://api.nuget.org/v3/index.json"
}
}
}
}
}
}
}
def getTypeOfVersion(branchName) {
def matcher = (branchName =~ /(v[\d.]+|release\/[\d.]+|master)/)
if (matcher.matches())
return ""
return "dev"
}
def getConfiguration(branchName) {
def matcher = (branchName =~ /(release\/[\d.]+|master)/)
if (matcher.matches())
return "Release"
return "Debug"
}
def getVersionFromCsProj (csProjFilePath){
def file = readFile(csProjFilePath)
def xml = new XmlSlurper().parseText(file)
def suffix = ""
if ( xml.PropertyGroup.VersionSuffix[0].text() != "" )
suffix = "-" + xml.PropertyGroup.VersionSuffix[0].text()
return xml.PropertyGroup.Version[0].text() + suffix
}