-
Notifications
You must be signed in to change notification settings - Fork 8
/
Jenkinsfile
78 lines (69 loc) · 2.22 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
// Config
class Globals {
static String GitRepo = 'https://github.com/Xainey/PSHitchhiker.git'
static String ModuleName = 'PSHitchhiker'
static String JenkinsChannel = '#jenkins-channel'
}
// Workflow Steps
node('master') {
try {
notifyBuild('STARTED')
stage('Stage 0: Clone') {
git url: Globals.GitRepo
}
stage('Stage 1: Clean') {
posh 'Invoke-Build Clean'
}
stage('Stage 2: Analyze') {
posh 'Invoke-Build Analyze'
}
stage('Stage 3: Test') {
posh 'Invoke-Build RunTests'
step([$class: 'NUnitPublisher',
testResultsPattern: '**\\TestResults.xml',
debug: false,
keepJUnitReports: true,
skipJUnitArchiver:false,
failIfNoResults: true
])
publishHTML (target: [
allowMissing: false,
alwaysLinkToLastBuild: true,
keepAll: true,
reportDir: 'artifacts',
reportFiles: 'TestReport.htm',
reportName: "PowerShell Test Report"
])
posh 'Invoke-Build ConfirmTestsPassed'
}
stage('Stage 4: Archive') {
posh 'Invoke-Build Archive'
archiveArtifacts artifacts: "artifacts/${Globals.ModuleName}.zip", onlyIfSuccessful: true
archiveArtifacts artifacts: "artifacts/${Globals.ModuleName}.*.nupkg", onlyIfSuccessful: true
}
stage('Stage 5: Publish') {
timeout(20) {
posh 'Invoke-Build Publish'
}
}
} catch (e) {
currentBuild.result = "FAILED"
throw e
} finally {
notifyBuild(currentBuild.result)
}
}
// Helper function to run PowerShell Commands
def posh(cmd) {
bat 'powershell.exe -NonInteractive -NoProfile -ExecutionPolicy Bypass -Command "& ' + cmd + '"'
}
// Helper function to Broadcast Build to Slack
def notifyBuild(String buildStatus = 'STARTED') {
buildStatus = buildStatus ?: 'SUCCESSFUL'
def colorCode = '#FF0000' // Failed : Red
if (buildStatus == 'STARTED') { colorCode = '#FFFF00' } // STARTED: Yellow
else if (buildStatus == 'SUCCESSFUL') { colorCode = '#00FF00' } // SUCCESSFUL: Green
def subject = "${buildStatus}: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'"
def summary = "${subject} (${env.BUILD_URL})"
slackSend (color: colorCode, channel: "${Globals.JenkinsChannel}", message: summary)
}