forked from OasisLMF/ODS_OpenExposureData
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
118 lines (106 loc) · 4.94 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
node {
hasFailed = false
sh 'sudo /var/lib/jenkins/jenkins-chown'
deleteDir() // wipe out the workspace
properties([
parameters([
[$class: 'StringParameterDefinition', name: 'ODS_BRANCH', defaultValue: BRANCH_NAME],
[$class: 'StringParameterDefinition', name: 'PUBLISH_VERSION', defaultValue: ''],
[$class: 'BooleanParameterDefinition', name: 'PUBLISH', defaultValue: Boolean.valueOf(false)],
[$class: 'BooleanParameterDefinition', name: 'GH_PAGES', defaultValue: Boolean.valueOf(false)],
[$class: 'BooleanParameterDefinition', name: 'AUTO_MERGE', defaultValue: Boolean.valueOf(true)],
[$class: 'BooleanParameterDefinition', name: 'SLACK_MESSAGE', defaultValue: Boolean.valueOf(false)]
])
])
//String Vars
hasFailed = false
String git_creds = "1335b248-336a-47a9-b0f6-9f7314d6f1f4"
String ods_git = "[email protected]:OasisLMF/OpenDataStandards.git"
String ods_branch = params.ODS_BRANCH
String ods_dir = "oasis_ods_build"
String ods_pages = "oasis_ods_pages"
//Env vars
env.TAG_RELEASE = params.PUBLISH_VERSION
try {
stage('Clone: OpenDataStandards') {
sshagent (credentials: [git_creds]) {
dir(ods_dir) {
sh "git clone -b ${ods_branch} ${ods_git} ."
}
}
}
stage('Run: ODE Build') {
dir(ods_dir) {
sh 'docker build -f docker/Dockerfile.oasis_docbuilder -t oed_doc_builder .'
sh 'docker run -v $(pwd):/tmp/output oed_doc_builder:latest'
}
}
if (params.GH_PAGES){
stage('Publish: GitHub Pages') {
dir(ods_pages) {
sshagent (credentials: [git_creds]) {
// Copy github pages branch
sh "git clone -b gh_pages ${ods_git} ."
// Extract new html & push
sh "tar -zxvf ${env.WORKSPACE}/${ods_dir}/oed_docs.tar.gz -C ."
sh "git add *"
sh "git status"
sh "git commit -m 'Update documenation - v${params.PUBLISH_VERSION}'"
sh "git push"
}
}
}
}
if(params.PUBLISH){
stage('Publish: GitHub') {
dir(ods_dir) {
sshagent (credentials: [git_creds]) {
sh "git tag ${env.TAG_RELEASE}"
sh "git push origin ${env.TAG_RELEASE}"
}
// Create Release
withCredentials([string(credentialsId: 'github-api-token', variable: 'gh_token')]) {
String repo = "OasisLMF/OpenDataStandards"
def json_request = readJSON text: '{}'
json_request['tag_name'] = env.TAG_RELEASE
json_request['target_commitish'] = 'master'
json_request['name'] = env.TAG_RELEASE
json_request['body'] = ""
json_request['draft'] = false
json_request['prerelease'] = false
writeJSON file: 'gh_request.json', json: json_request
sh 'curl -XPOST -H "Authorization:token ' + gh_token + "\" --data @gh_request.json https://api.github.com/repos/$repo/releases > gh_response.json"
}
}
}
}
} catch(hudson.AbortException | org.jenkinsci.plugins.workflow.steps.FlowInterruptedException buildException) {
hasFailed = true
error('Build Failed')
} finally {
if(params.SLACK_MESSAGE && (params.PUBLISH || hasFailed)){
def slackColor = hasFailed ? '#FF0000' : '#27AE60'
SLACK_MSG = "*${env.JOB_NAME}* - (<${env.BUILD_URL}|${env.RELEASE_TAG}>): " + (hasFailed ? 'FAILED' : 'PASSED')
SLACK_MSG += "\nMode: " + (params.PUBLISH ? 'Publish' : 'Build Test')
SLACK_CHAN = (params.PUBLISH ? "#builds-release":"#builds-dev")
slackSend(channel: SLACK_CHAN, message: SLACK_MSG, color: slackColor)
}
// Store build output
dir(ods_dir) {
archiveArtifacts artifacts: '*.tar.gz'
archiveArtifacts artifacts: '*.pdf'
}
// Run merge back if publish
if (params.PUBLISH && params.AUTO_MERGE){
dir(ods_dir) {
sshagent (credentials: [git_creds]) {
sh "git stash"
sh "git checkout master && git pull"
sh "git merge ${ods_branch} && git push"
sh "git checkout develop && git pull"
sh "git merge master && git push"
}
}
}
}
}