This repository has been archived by the owner on Feb 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJenkinsfile
68 lines (56 loc) · 2.7 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
#!groovy
milestone 0
node('docker') {
slackJobDescription = "job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})"
try {
stage "Build"
checkout scm
repo = sh(returnStdout: true, script: 'grep "(defproject" project.clj | sed -E \'s%.defproject[^/]*/?([^ ]+) .*%\\1%\'').trim()
echo repo
descriptive_version = sh(returnStdout: true, script: 'git describe --long --tags --dirty --always').trim()
echo descriptive_version
dockerRepo = "test-${env.BUILD_TAG}"
sh "docker build --rm -t ${dockerRepo} ."
dockerTestRunner = "test-${env.BUILD_TAG}"
dockerTestCleanup = "test-cleanup-${env.BUILD_TAG}"
dockerDeployer = "deploy-${env.BUILD_TAG}"
try {
stage "Test"
try {
sh "docker run --rm --name ${dockerTestRunner} -v \$(pwd)/test2junit:/usr/src/app/test2junit ${dockerRepo}"
} finally {
junit 'test2junit/xml/*.xml'
sh "docker run --rm --name ${dockerTestCleanup} -v \$(pwd):/build -w /build alpine rm -r test2junit"
}
milestone 100
stage "Deploy"
lock("lein-deploy-${env.JOB_NAME}") {
milestone 101
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'jenkins-clojars-credentials', usernameVariable: 'LEIN_USERNAME', passwordVariable: 'LEIN_PASSWORD']]) {
sh "docker run --name ${dockerDeployer} -e LEIN_USERNAME -e LEIN_PASSWORD --rm ${dockerRepo} lein deploy"
}
}
} finally {
sh returnStatus: true, script: "docker kill ${dockerTestRunner}"
sh returnStatus: true, script: "docker rm ${dockerTestRunner}"
sh returnStatus: true, script: "docker kill ${dockerTestCleanup}"
sh returnStatus: true, script: "docker rm ${dockerTestCleanup}"
sh returnStatus: true, script: "docker kill ${dockerDeployer}"
sh returnStatus: true, script: "docker rm ${dockerDeployer}"
sh returnStatus: true, script: "docker rmi ${dockerRepo}"
step([$class: 'hudson.plugins.jira.JiraIssueUpdater',
issueSelector: [$class: 'hudson.plugins.jira.selector.DefaultIssueSelector'],
scm: scm,
labels: [ "${repo}-${descriptive_version}" ]])
}
} catch (InterruptedException e) {
currentBuild.result = "ABORTED"
slackSend color: 'warning', message: "ABORTED: ${slackJobDescription}"
throw e
} catch (e) {
currentBuild.result = "FAILED"
sh "echo ${e}"
slackSend color: 'danger', message: "FAILED: ${slackJobDescription}"
throw e
}
}