Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds an interface to talk to Jenkins #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Sources/SwiftServer/main.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import Kitura
import KituraNet
import HeliumLogger
import LoggerAPI
import MongoKitten
import Environment
import SwiftServerLibrary
import SwiftyJSON
import Foundation

HeliumLogger.use()

Expand Down Expand Up @@ -31,6 +34,16 @@ do {
next()
}

router.get("/jenkins") {request, response, next in
JenkinsService.fetchLatestBuild({ (buildNumber, status) in
let displayString = "\(buildNumber) - \(status)"
response.send(displayString)
next()
})
}



Kitura.addHTTPServer(onPort: 8090, with: router)
Kitura.run()
} catch {
Expand Down
27 changes: 27 additions & 0 deletions Sources/SwiftServerLibrary/JenkinsService.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import KituraNet
import Foundation
import SwiftyJSON


public struct JenkinsService {
public enum Status: String {
case Success = "SUCCESS", Failure = "FAILURE"
}


public static func fetchLatestBuild(_ completionHandler : (String, Status) -> Void) {
let URL = "http://cijenkins04.rnd.in.here.com:8080/job/team-heresuite/job/hereapp-ios/job/master/job/post-submit/job/Trigger/lastCompletedBuild/api/json?pretty=false"
let _ = HTTP.get(URL, callback: { (jenkinsResponse) in

var data = Data()
try! jenkinsResponse!.readAllData(into: &data)
let dict = JSON(data: data)

if let result = dict["result"].string,
let status = JenkinsService.Status(rawValue: result) {
let buildNumber = dict["number"].stringValue
completionHandler(buildNumber, status)
}
})
}
}