-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
84 lines (83 loc) · 4.13 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
node {
def artifactoryServer = Artifactory.server 'Lipidomics'
def toolName = "${jobToolName?:''}"
def emailOnSuccess = "${jobEmailRecipients?:''}"
def emailOnFailure = "${jobEmailRecipients?:''}"
def gitRepo = "${jobRepo?:'kopczynski/cppgoslin'}"
def gitHoster = "gitlab.isas.de"
def gitUrl = "https://${gitHoster}/${gitRepo}"
def gitUserName = "${jobGitUserName?:''}"
def gitUserEmail = "${jobGitUserEmail?:''}"
def gitUserCredentialsId = "${jobGitUserCredentials?:''}"
def dockerRegistryUrl = "${jobDockerRegistryUrl?:''}"
def dockerRegistryCredentialsId = "${jobDockerRegistryCredentialsId?:''}"
def dockerBuildImage = "${jobDockerBuildImage?:''}"
def afUploadSpec = """{
"files": [
{
"pattern": "LipidCreator/bin/x64/Release/LipidCreator.zip",
"target": "libs-release-local/de/isas/lipidomics/lipidcreator/${BUILD_NUMBER}/LipidCreator-${BUILD_NUMBER}.zip",
"props": "artifactId:lipidcreator;groupId:de.isas.lipidomics;type:zip;version:${BUILD_NUMBER}",
"recursive": "false",
"flat" : "true",
"regexp": "false"
},
{
"pattern": "LipidCreator/bin/x64/Release/LipidCreator.zip",
"target": "libs-release-local/de/isas/lipidomics/lipidcreator/${BUILD_NUMBER}/LipidCreator.zip",
"props": "artifactId:lipidcreator;groupId:de.isas.lipidomics;type:zip;version:${BUILD_NUMBER}",
"recursive": "false",
"flat" : "true",
"regexp": "false"
}
]
}"""
stage('Build & Test') {
docker.withRegistry(dockerRegistryUrl, dockerRegistryCredentialsId) {
docker.image(dockerBuildImage).inside {
try {
stage 'Checkout'
def scmVars = checkout([$class: 'GitSCM', branches: [[name: '*/master']],
extensions: scm.extensions + [[$class: 'WipeWorkspace']],
userRemoteConfigs: [[credentialsId: gitUserCredentialsId, url: gitUrl]]])
script {
env.GIT_COMMIT = scmVars.GIT_COMMIT
env.GIT_BRANCH = scmVars.GIT_BRANCH
}
stage 'Build'
sh 'make'
stage 'Test'
sh 'make test && make runtests'
// stage('Publish') {
// def buildInfo = artifactoryServer.upload spec: afUploadSpec, failNoOp: true
// artifactoryServer.publishBuildInfo buildInfo
// }
stage 'Tag'
withCredentials([usernamePassword(credentialsId: gitUserCredentialsId, passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME')]) {
sh("git config user.email '${jobGitUserEmail}'")
sh("git config user.name '${jobGitUserName}'")
sh("git tag -a '${BUILD_NUMBER}' -m 'Automatic tag for successful build number ${BUILD_NUMBER} from commit ${GIT_COMMIT} on branch ${GIT_BRANCH}'")
script {
env.encodedPass=URLEncoder.encode("${GIT_PASSWORD}", "UTF-8")
env.gitHoster=gitHoster
env.gitRepo=gitRepo
}
sh('git push https://${GIT_USERNAME}:${encodedPass}@${gitHoster}/${gitRepo} --tags')
}
stage 'Notify'
mail to: emailOnSuccess,
subject: "${toolName} build succeeded: ${currentBuild.fullDisplayName}",
body: "Artifacts have been deployed to Artifactory, build tag was pushed to ${gitUrl}/releases/tag/${BUILD_NUMBER}."
} catch(e) {
mail to: emailOnFailure,
subject: "${toolName} build failed: ${currentBuild.fullDisplayName}",
body: """Please check the job errors:
${e}
"""
throw e
} finally {
}
}
}
}
}