-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathJenkinsfile
More file actions
81 lines (79 loc) · 3.12 KB
/
Jenkinsfile
File metadata and controls
81 lines (79 loc) · 3.12 KB
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
pipeline {
agent {
docker {
image 'mcr.microsoft.com/dotnet/sdk:6.0'
}
}
environment {
NUGET_API_SOURCE = credentials('NUGET_API_SOURCE')
NUGET_TOKEN = credentials('NUGET_TOKEN')
MANIFEST_PATH = '.manifest.json'
}
stages {
stage('Run Only on Tag') {
when {
expression {
// Matches tags like rls_0.1.0, rls_0.1.1, etc.
return env.BRANCH_NAME ==~ /^rls_\d+\.\d+\.\d+$/
}
}
steps {
echo "Running on tag: $env.BRANCH_NAME"
}
stages {
stage('Pre-check for Environment Variables') {
steps {
script {
if (!env.NUGET_API_SOURCE || !env.NUGET_TOKEN) {
error("Error: NUGET_API_SOURCE or NUGET_TOKEN is not defined")
}
echo "Environment variables are defined."
}
}
}
stage('Read .csproj file path and SDK version') {
steps {
sh '''
apt-get update && apt-get install -y jq
csproj_path=$(jq -r '.files[] | select(endswith(".csproj") and (. | endswith("Example.csproj") | not))' $MANIFEST_PATH)
if [ -z "$csproj_path" ]; then
echo "Error: csproj_path is not defined"
exit 1
fi
echo "Project path: $csproj_path"
sdk_version=$(jq -r '.config.sdkVersion' $MANIFEST_PATH)
if [ -z "$sdk_version" ]; then
echo "Error: sdk_version is not defined"
exit 1
fi
echo "SDK Version: $sdk_version"
echo "csproj_path=${csproj_path}" > csproj_path.txt
echo "sdk_version=${sdk_version}" > sdk_version.txt
'''
}
}
stage('Setup .NET and Pack NuGet Package') {
steps {
script {
def csprojPath = readFile('csproj_path.txt').trim()
def sdkVersion = readFile('sdk_version.txt').trim()
sh "dotnet pack ${csprojPath} -o ./dist --configuration Release /p:PackageVersion=${sdkVersion}"
}
}
}
stage('Publish NuGet Package') {
steps {
sh '''
dotnet nuget push ./dist/*.nupkg --api-key ${NUGET_TOKEN} --source ${NUGET_API_SOURCE}
'''
}
}
}
}
}
post {
always {
cleanWs()
}
}
}