forked from stefanprodan/dockerdash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
86 lines (70 loc) · 3.3 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
79
80
81
82
83
84
85
#!groovy
import groovy.json.JsonSlurperClassic
def getVersion(def projectJson){
def slurper = new JsonSlurperClassic()
project = slurper.parseText(projectJson)
slurper = null
return project.version.split('-')[0]
}
def version, revision
node {
stage('Checkout') {
checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false,
extensions: [[$class: 'CleanBeforeCheckout']],
submoduleCfg: [],
userRemoteConfigs: [[credentialsId: 'spgit', url: 'https://github.com/stefanprodan/dockerdash']]])
version = getVersion(readFile('src/DockerDash/project.json'))
revision = version + "-" + sprintf("%04d", env.BUILD_NUMBER.toInteger())
println "Start building version $version revision $revision"
}
stage('Build test image') {
def dotnet = docker.image('microsoft/dotnet:latest')
dotnet.inside("-u root -e DOCKERDASH_USER='admin' -e DOCKERDASH_PASSWORD='changeme' -e DOCKER_REMOTE_API='unix:///var/run/docker.sock'") {
stage('Restore packages') {
// restore NuGet packages for all projects in solution
sh("dotnet restore")
}
stage('Compile project') {
sh("dotnet build src/DockerDash -c Release")
}
stage('Run tests') {
try{
sh("dotnet test test/DockerDash.Tests -c Release -xml testresult.xml")
}catch(err){
// test failed
}
step([$class: 'XUnitBuilder', testTimeMargin: '3000', thresholdMode: 1,
thresholds:
[[$class: 'FailedThreshold', failureNewThreshold: '0', failureThreshold: '0', unstableNewThreshold: '0', unstableThreshold: '0'],
[$class: 'SkippedThreshold', failureNewThreshold: '1', failureThreshold: '1', unstableNewThreshold: '0', unstableThreshold: '0']],
tools: [[$class: 'XUnitDotNetTestType',
deleteOutputFiles: true,
failIfNotNew: false,
pattern: 'testresult.xml', skipNoTestFiles: true, stopProcessingIfError: true]]])
}
stage('Publish artifacts') {
// publish web app to the release dir
sh("mkdir release")
sh("dotnet publish -c Release -o \$(pwd)/release src/DockerDash")
archiveArtifacts artifacts: 'release/**/*', fingerprint: true
}
// give jenkins user ownership of build artifacts
sh("chown -R 1000 src")
sh("chown -R 1000 test")
sh("chown -R 1000 release")
}
}
stage('Publish image') {
def image = docker.build("dockerdash:$revision")
docker.withRegistry("https://nexus.cifire.com", "nexus") {
image.push()
image.push('latest')
}
}
stage('Remove local images') {
// remove docker images
sh("docker rmi -f nexus.cifire.com/dockerdash:latest || :")
sh("docker rmi -f nexus.cifire.com/dockerdash:$revision || :")
sh("docker rmi -f dockerdash:$revision || :")
}
}