-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathjenkinsfile.groovy
74 lines (65 loc) · 2.51 KB
/
jenkinsfile.groovy
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
def isRelease() {
return env.IS_RELEASE_JOB == "true"
}
def version() {
return sh(returnStdout: true, script: "node -p \"require('./package.json').version\"").trim()
}
def onRelease(Closure body) {
if (isRelease()) {
body(version())
}
}
node("JenkinsOnDemand") {
def organization = 'Hydrospheredata'
def repository = 'mist-ui'
def accessTokenId = 'HydroRobot_AccessToken'
stage("Checkout") {
def branches = (isRelease()) ? [[name: env.BRANCH_NAME]] : scm.branches
checkout([
$class: 'GitSCM',
branches: branches,
doGenerateSubmoduleConfigurations: scm.doGenerateSubmoduleConfigurations,
extensions: [[$class: 'CloneOption', noTags: false, shallow: false, depth: 0, reference: '']],
userRemoteConfigs: scm.userRemoteConfigs,
])
}
stage("Build") {
sh "npm install"
sh "npm run build-prod-tar"
}
if (currentBuild.result == 'UNSTABLE') {
currentBuild.result = 'FAILURE'
error("Errors in tests")
}
onRelease { version ->
stage("Create GitHub Release") {
echo "Release ${version}"
def releaseFile = "mist-ui-${version}.tar.gz"
withCredentials([[
$class: 'UsernamePasswordMultiBinding',
credentialsId: accessTokenId,
usernameVariable: 'GIT_USERNAME',
passwordVariable: 'GIT_PASSWORD']]) {
def request = """
{
"tag_name": "v${version}",
"name": "${version}",
"body": "${version}",
"draft": false,
"prerelease": false
}
"""
echo request
def response = httpRequest consoleLogResponseBody: true, acceptType: 'APPLICATION_JSON', contentType: 'APPLICATION_JSON', httpMode: 'POST', requestBody: request, url: "https://api.github.com/repos/${organization}/${repository}/releases?access_token=${GIT_PASSWORD}"
def releaseInfo = response.content
def props = readJSON text: "${releaseInfo}"
def releaseId = props.id
sh """curl --data-binary @"${releaseFile}" -H "Authorization: token ${
GIT_PASSWORD
}" -H "Content-Type: application/zip" https://uploads.github.com/repos/${organization}/${repository}/releases/${
releaseId
}/assets?name=${releaseFile}"""
}
}
}
}