Created
May 3, 2017 11:07
-
-
Save garethahealy/5e43e3cf192c8bd20286cd2335abce0e to your computer and use it in GitHub Desktop.
shitty groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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