Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save garethahealy/5e43e3cf192c8bd20286cd2335abce0e to your computer and use it in GitHub Desktop.
Save garethahealy/5e43e3cf192c8bd20286cd2335abce0e to your computer and use it in GitHub Desktop.
shitty groovy
def createOrApplyResource( String project, String resourcePath, String appName) {
def countScript = $/eval "oc project ${project} | oc get is ${appName} --no-headers -n ${project} | wc -l | xargs"/$
def resourceCountRaw = sh returnStdout: true, script: "${countScript}"
if ( resourceCountRaw.equalsIgnoreCase("0") ) {
sh "oc project ${project} && oc create -f ${resourcePath} -n ${project}"
} else if ( resourceCountRaw.equalsIgnoreCase("1") ) {
sh "oc project ${project} && oc apply -f ${resourcePath} -n ${project}"
} else {
sh "echo 'Unknown response: resourceCountRaw == ${resourceCountRaw}'"
currentBuild.result = 'FAILURE'
throw new RuntimeException("Unknown response")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment