Skip to content

Commit

Permalink
Merge pull request #40 from sthaha/develop
Browse files Browse the repository at this point in the history
build/deploy: use oc image by default
  • Loading branch information
sthaha authored Oct 2, 2018
2 parents ef2345a + 3698223 commit d662730
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 31 deletions.
64 changes: 34 additions & 30 deletions vars/build.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,47 @@ import io.openshift.Events
import io.openshift.Utils

def call(Map args) {
stage("Build application") {
if (!args.resources) {
error "Missing manadatory parameter: resources"
}
stage("Build application") {
if (!args.resources) {
error "Missing manadatory parameter: resources"
}


// can pass single or multiple maps
def res = Utils.mergeResources(args.resources)
// can pass single or multiple maps
def res = Utils.mergeResources(args.resources)

def required = ['ImageStream', 'BuildConfig']
def found = res.keySet()
def missing = required - found
if (missing) {
error "Missing mandatory build resources params: $missing; found: $found"
}
def required = ['ImageStream', 'BuildConfig']
def found = res.keySet()
def missing = required - found
if (missing) {
error "Missing mandatory build resources params: $missing; found: $found"
}

def namespace = args.namespace ?: Utils.usersNamespace()
def image = config.runtime() ?: 'oc'

def status = ""
spawn(image: image, version: config.version(), commands: args.commands) {
Events.emit("build.start")
try {
createImageStream(res.ImageStream, namespace)
buildProject(res.BuildConfig, namespace)
status = "pass"
} catch (e) {
status = "fail"
} finally {
Events.emit(["build.end", "build.${status}"], [status: status, namespace: namespace])
}
def namespace = args.namespace ?: Utils.usersNamespace()

if (status == 'fail') {
error "Build failed"
}
def image = args.image
if (!image) {
image = args.commands ? config.runtime() : 'oc'
}

def status = ""
spawn(image: image, version: config.version(), commands: args.commands) {
Events.emit("build.start")
try {
createImageStream(res.ImageStream, namespace)
buildProject(res.BuildConfig, namespace)
status = "pass"
} catch (e) {
status = "fail"
} finally {
Events.emit(["build.end", "build.${status}"], [status: status, namespace: namespace])
}

if (status == 'fail') {
error "Build failed"
}
}
}
}

def createImageStream(imageStreams, namespace) {
Expand Down
6 changes: 5 additions & 1 deletion vars/deploy.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ def call(Map args = [:]) {
}
}

def image = config.runtime() ?: 'oc'
def image = args.image
if (!image) {
image = args.commands ? config.runtime() : 'oc'
}

stage("Deploy to ${args.env}") {
spawn(image: image) {
def userNS = Utils.usersNamespace();
Expand Down

0 comments on commit d662730

Please sign in to comment.