-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathJenkinsFile
72 lines (69 loc) · 3.09 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
#!/usr/bin/groovy
node {
def root = pwd()
def mvn = tool 'M3'
def golangTool = tool 'golang_1.7'
def appvers = ""
stage("Config") {
// clone the configuration repository and copy the current configuration
def configDir = "${root}/configuration"
def configFile = "${root}/config.json"
dir(configDir) {
git url: "${env.CONFIGURATION_URL}", credentialsId: "${env.CONFIGURATION_CREDS}"
sh "mv ${configDir}/${ENVIRONMENT}-config.json ${configFile}"
deleteDir()
}
// read the current configuration
def configJson = readJSON file: "${configFile}"
for (param in configJson.credparams + configJson.jobparams) {
env."${param.name}" = (param.type == "booleanParam") ? "${param.defaultvalue}".toBoolean() : "${param.defaultvalue}"
}
}
stage("Setup") {
deleteDir()
withEnv([
"PATH+=${golangTool}/bin:${root}/gopath/bin",
"GOROOT=${golangTool}",
"GOPATH=${root}/gopath"
]) {
sh """
mkdir -p ${root}/gopath/bin ${root}/gopath/pkg ${root}/gopath/src/github.com/venicegeo/geojson-go
go version
"""
}
dir("${root}/gopath/src/github.com/venicegeo/geojson-go") {
if(env.USE_GIT_CREDS.toBoolean()) {
git url: "${env.GIT_URL}", branch: "${env.GIT_BRANCH}", credentialsId: "${env.GITLAB_CREDS}"
} else {
git url: "${env.GIT_URL}", branch: "${env.GIT_BRANCH}"
}
appvers = sh(script: """git describe --long --tags --always | sed 's/\\./-/'g""", returnStdout: true).trim()
}
}
def appName = "geojson-go-${appvers}"
stage("Archive") {
def archiveName = "geojson-go.tgz"
withEnv([
"PATH+=${golangTool}/bin:${root}/gopath/bin",
"GOROOT=${golangTool}",
"GOPATH=${root}/gopath"
]) {
sh """
cd "\$GOPATH/src/github.com/venicegeo/geojson-go"
cd geojson
go test -v -coverprofile=${root}/geojson.cov
cd ${root}
go tool cover -func=geojson.cov -o geojson.cov.txt
tar -cvzf ${archiveName} *.cov*
"""
def getDependencyStatus = sh(script: """mvn --quiet --settings ~/.m2/settings.xml dependency:get -Dmaven.repo.local="${root}/.m2/repository" -DrepositoryId=nexus -DartifactId=geojson-go -Dversion=${appvers} -DgroupId="org.venice.beachfront" -Dpackaging=tgz -DremoteRepositories="nexus::default::${env.ARTIFACT_STORAGE_DEPLOY_URL}" >> /dev/null 2>&1""", returnStatus: true)
if(getDependencyStatus == 0) {
echo "Artifact version ${appvers} exists in Nexus, nothing to do"
} else {
sh """
mvn -X --settings ~/.m2/settings.xml deploy:deploy-file -Dfile=${archiveName} -DrepositoryId=nexus -Durl="${env.ARTIFACT_STORAGE_DEPLOY_URL}" -DgroupId="org.venice.beachfront" -DgeneratePom=false -Dpackaging=tgz -Dmaven.repo.local="${root}/.m2/repository" -DartifactId=geojson-go -Dversion=${appvers}
"""
}
}
}
}