-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
132 lines (114 loc) · 4.49 KB
/
Jenkinsfile
File metadata and controls
132 lines (114 loc) · 4.49 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
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
pipeline {
agent {
label 'windows' // Requires a Windows agent with .NET SDK installed
}
environment {
DOTNET_CLI_TELEMETRY_OPTOUT = '1'
DOTNET_NOLOGO = '1'
PROJECT_NAME = 'ImageProcessor'
SOLUTION_FILE = 'ImageProcessor.sln'
PUBLISH_DIR = 'publish'
ARTIFACT_NAME = "ImageProcessor-${env.BUILD_NUMBER}"
}
options {
buildDiscarder(logRotator(numToKeepStr: '10'))
timestamps()
timeout(time: 30, unit: 'MINUTES')
}
stages {
stage('Checkout') {
steps {
checkout scm
echo "Building branch: ${env.BRANCH_NAME ?: 'master'}"
echo "Build number: ${env.BUILD_NUMBER}"
}
}
stage('Restore') {
steps {
bat 'dotnet restore %SOLUTION_FILE%'
}
}
stage('Build') {
steps {
bat 'dotnet build %SOLUTION_FILE% --configuration Release --no-restore'
}
}
stage('Test') {
steps {
echo 'Running tests...'
// Uncomment when tests are added
// bat 'dotnet test %SOLUTION_FILE% --configuration Release --no-build --verbosity normal'
echo 'No tests configured yet - skipping'
}
}
stage('Publish') {
steps {
echo 'Publishing self-contained executable...'
bat '''
dotnet publish %PROJECT_NAME%\\%PROJECT_NAME%.csproj ^
--configuration Release ^
--runtime win-x64 ^
--self-contained true ^
--output %PUBLISH_DIR%\\win-x64 ^
-p:PublishSingleFile=true ^
-p:IncludeNativeLibrariesForSelfExtract=true ^
-p:EnableCompressionInSingleFile=true
'''
}
}
stage('Archive Artifacts') {
steps {
echo 'Archiving build artifacts...'
// Create version info file
bat '''
echo Build: %BUILD_NUMBER% > %PUBLISH_DIR%\\win-x64\\version.txt
echo Date: %DATE% %TIME% >> %PUBLISH_DIR%\\win-x64\\version.txt
echo Branch: %BRANCH_NAME% >> %PUBLISH_DIR%\\win-x64\\version.txt
'''
// Archive the published files
archiveArtifacts artifacts: "${PUBLISH_DIR}/win-x64/**/*", fingerprint: true
// Create a zip file for distribution
bat '''
powershell -Command "Compress-Archive -Path '%PUBLISH_DIR%\\win-x64\\*' -DestinationPath '%PUBLISH_DIR%\\%ARTIFACT_NAME%.zip' -Force"
'''
archiveArtifacts artifacts: "${PUBLISH_DIR}/${ARTIFACT_NAME}.zip", fingerprint: true
}
}
stage('Deploy to Production') {
when {
anyOf {
branch 'master'
branch 'main'
}
}
steps {
echo 'Deploying to production server...'
// Option 1: Copy to network share
// bat 'xcopy /Y /E %PUBLISH_DIR%\\win-x64\\* \\\\production-server\\apps\\ImageProcessor\\'
// Option 2: Copy to local production folder
// bat 'xcopy /Y /E %PUBLISH_DIR%\\win-x64\\* C:\\Production\\ImageProcessor\\'
// Option 3: Use SSH/SCP to deploy to remote server
// bat 'scp -r %PUBLISH_DIR%\\win-x64\\* user@production-server:/opt/apps/ImageProcessor/'
echo 'Deployment target not configured - update Jenkinsfile with your production server details'
echo "Artifacts available at: ${env.BUILD_URL}artifact/${PUBLISH_DIR}/"
}
}
}
post {
success {
echo 'Build completed successfully!'
echo "Download artifacts from: ${env.BUILD_URL}artifact/"
}
failure {
echo 'Build failed!'
// Uncomment to enable email notifications
// mail to: 'team@example.com',
// subject: "Build Failed: ${env.JOB_NAME} #${env.BUILD_NUMBER}",
// body: "Check console output at ${env.BUILD_URL}"
}
cleanup {
echo 'Cleaning up workspace...'
// cleanWs() // Uncomment to clean workspace after build
}
}
}