forked from IQSS/dataverse
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJenkinsfile
93 lines (83 loc) · 2.55 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
86
87
88
89
90
91
92
93
#!/usr/bin/env groovy
node {
workspace = pwd()
properties([[$class: 'ParametersDefinitionProperty', parameterDefinitions: [
[ name: 'DEPLOY_TARGET', $class: 'StringParameterDefinition', defaultValue: 'qdr-dev' ],
]]])
withCredentials([
string(credentialsId: 'dataverse-deploy-user ', variable: 'DATAVERSE_DEPLOY_USER'),
string(credentialsId: 'GRAPHITE_URL ', variable: 'GRAPHITE_URL'),
]) {
stage('Init') {
/*
* Checkout code
*/
checkout scm
ARTIFACT_ID = readMavenPom().getArtifactId()
VERSION = readMavenPom(file: 'modules/dataverse-parent/pom.xml').getVersion()
currentBuild.result = 'SUCCESS'
}
stage('Test') {
/*
* Run Unit tests
*/
notifyBuild("Running tests..", "good")
try {
withMaven(
//jdk: 'jdk17',
maven: 'mvn-3-6') {
sh "mvn test"
}
}
catch (e) {
currentBuild.result = "UNSTABLE"
notifyBuild("Tests failed!", "warning")
}
}
stage('Build') {
/*
* Run Unit tests
*/
notifyBuild("Building..", "good")
try {
withMaven(
//jdk: 'jdk17',
maven: 'mvn-3-6') {
sh "mvn clean package -DskipTests"
}
}
catch (e) {
currentBuild.result = "FAILURE"
notifyBuild("Build failed!", "warning")
}
stash includes: 'target/dataverse*.war', name: 'dataverse-war'
}
stage('Deploy') {
/*
* Deploy
*/
timeout(time: 2, unit: "HOURS") {
def DEPLOY_TARGET = input message: 'Deploy to', parameters: [string(defaultValue: "${DEPLOY_TARGET}", description: 'qdr-dev, qdr-stage, qdr-prod', name: 'DEPLOY_TARGET')]
}
notifyBuild("Deploying ${ARTIFACT_ID}-${VERSION} to ${DEPLOY_TARGET}", "good")
unstash 'dataverse-war'
try {
sh """
rsync -av target/${ARTIFACT_ID}-${VERSION}.war ${DATAVERSE_DEPLOY_USER}@${DEPLOY_TARGET}:/srv/dataverse-releases
ssh ${DATAVERSE_DEPLOY_USER}@${DEPLOY_TARGET} "dataverse-deploy ${ARTIFACT_ID} ${VERSION}"
"""
notifyBuild("Success", "good")
sh "curl -sX POST ${GRAPHITE_URL}/events/ -d '{\"what\": \"${ARTIFACT_ID}-${VERSION} to ${DEPLOY_TARGET}\", \"tags\" : \"deployment\"}'"
}
catch (e) {
currentBuild.result = "FAILURE"
notifyBuild("Deploy failed!", "danger")
throw e
}
}
}
}
@NonCPS
def notifyBuild(String message, String color) {
slackSend message: "<$JOB_URL|$JOB_NAME>: ${message}", color: "${color}"
}