-
Notifications
You must be signed in to change notification settings - Fork 21
/
Jenkinsfile
49 lines (40 loc) · 1.87 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
node {
def scmVars
stage('build') {
// Use Maven Tool
env.PATH="${tool 'M3'}/bin:${env.PATH}"
scmVars = checkout scm
// Run Build
sh 'mvn clean install'
}
stage('Deploy') {
def environment = "Prod"
def description = "Deploying my branch"
def ref = scmVars.GIT_COMMIT
def owner = "issc29"
def repo = "jenkins-deployment-api"
def deployURL = "https://api.github.com/repos/${owner}/${repo}/deployments"
def deployBody = '{"ref": "' + ref +'","environment": "' + environment +'","description": "' + description + '"}'
// Create new Deployment using the GitHub Deployment API
def response = httpRequest authentication: 'issc29-GH', httpMode: 'POST', requestBody: deployBody, responseHandle: 'STRING', url: deployURL
if(response.status != 201) {
error("Deployment API Create Failed: " + response.status)
}
// Get the ID of the GitHub Deployment just created
def responseJson = readJSON text: response.content
def id = responseJson.id
if(id == "") {
error("Could not extract id from Deployment response")
}
// Execute Deployment
def deployStatus = sh returnStatus: true, script: 'echo deploy'
// Record new Deployment Status based on output
def result = (deployStatus) ? 'failure' : 'success'
def deployStatusBody = '{"state": "' + result + '","target_url": "http://github.com/deploymentlogs"}'
def deployStatusURL = "https://api.github.com/repos/${owner}/${repo}/deployments/${id}/statuses"
def deployStatusResponse = httpRequest authentication: 'issc29-GH', httpMode: 'POST', requestBody: deployStatusBody , responseHandle: 'STRING', url: deployStatusURL
if(deployStatusResponse.status != 201) {
error("Deployment Status API Update Failed: " + deployStatusResponse.status)
}
}
}