diff --git a/src/main/groovy/ca/bc/gov/devops/OpenShiftBuildHelper.groovy b/src/main/groovy/ca/bc/gov/devops/OpenShiftBuildHelper.groovy index fc9344f..292a1e4 100644 --- a/src/main/groovy/ca/bc/gov/devops/OpenShiftBuildHelper.groovy +++ b/src/main/groovy/ca/bc/gov/devops/OpenShiftBuildHelper.groovy @@ -490,7 +490,10 @@ class OpenShiftBuildHelper extends OpenShiftHelper{ //sleepInSeconds=Math.max(sleepInSeconds, 5) triggered=true - }else if (images.size() == 1){ + }else { + if (images.size() > 1){ + println "WARNING: More than 1 image with the same build hash (${buildHash}) found for ${object.metadata.name} - ${images.values().collect({ it.name }).join(',')}" + } Map imageStreamImage = images.values()[0] println "Reusing existing image (${imageStreamImage.name}) for ${key(object)}" Map outputImageStreagTag = getImageStreamTag(outputTo) @@ -498,10 +501,6 @@ class OpenShiftBuildHelper extends OpenShiftHelper{ oc(['tag', '--source=imagestreamimage', "${outputTo.namespace?:config.app.build.namespace}/${outputTo.name.split(':')[0]}@${imageStreamImage.name}", "${outputTo.namespace?:config.app.build.namespace}/${outputTo.name}"]) } item.phase = 'Complete' - //Reuse Image from a previous build - }else{ - //hell broke loose! - throw new RuntimeException("More than 1 image with the same build hash found for ${object.metadata.name} - ${images.values().collect({ it.name }).join(',')}") } }else if ( 'Running' == item.phase || 'Pending' == item.phase){ Map build = ocGet(["${item['build-name']}", '-n', object.metadata.namespace]) diff --git a/src/main/groovy/ca/bc/gov/devops/OpenShiftDeploymentHelper.groovy b/src/main/groovy/ca/bc/gov/devops/OpenShiftDeploymentHelper.groovy index 1901b38..b82bab1 100644 --- a/src/main/groovy/ca/bc/gov/devops/OpenShiftDeploymentHelper.groovy +++ b/src/main/groovy/ca/bc/gov/devops/OpenShiftDeploymentHelper.groovy @@ -94,6 +94,8 @@ class OpenShiftDeploymentHelper extends OpenShiftHelper{ //Uncomment after removing 'oc tag' workaround //oc(['tag', "${config.app.build.namespace}/${buildImageStreamTagName}", "${object.metadata.namespace}/${deploymageStreamTagName}", '-n', object.metadata.namespace]) + //tag itself usin environment as to hold a link to the "latest" image for each environment + oc(['tag', "${buildImageStreamTagName}", "${object.metadata.name}:${deploymentConfig.env.name}", '-n', config.app.build.namespace]) } //println "${buildImageStreamTag}" //oc(['cancel-build', "bc/${object.metadata.name}", '-n', object.metadata.namespace]) diff --git a/src/main/groovy/ca/bc/gov/devops/OpenShiftHelper.groovy b/src/main/groovy/ca/bc/gov/devops/OpenShiftHelper.groovy index 8762144..b46809d 100644 --- a/src/main/groovy/ca/bc/gov/devops/OpenShiftHelper.groovy +++ b/src/main/groovy/ca/bc/gov/devops/OpenShiftHelper.groovy @@ -45,8 +45,8 @@ class OpenShiftHelper{ object.metadata.labels['app-name'] = config.app.name if (!'true'.equalsIgnoreCase(object.metadata.labels['shared'])){ if (config.app.git.uri.toLowerCase().startsWith('https://github.com/')) { - object.metadata.labels['github-owner'] = config.app.git.uri.tokenize('/')[2] - object.metadata.labels['github-repo'] = config.app.git.uri.tokenize('/')[3].tokenize('.git')[0] + object.metadata.labels['github-owner'] = config.app.git.uri.tokenize('/')[2].toLowerCase() + object.metadata.labels['github-repo'] = config.app.git.uri.tokenize('/')[3].reverse().substring(4).reverse().toLowerCase() } if (config.app?.git?.changeId){ diff --git a/src/main/resources/pipeline-cli b/src/main/resources/pipeline-cli index 4f89378..6afac12 100644 --- a/src/main/resources/pipeline-cli +++ b/src/main/resources/pipeline-cli @@ -95,23 +95,23 @@ export JAVACMD #echo "JAVACMD=${JAVACMD}" -GROOVY_DOWNLOAD_URL='https://dl.bintray.com/groovy/maven/apache-groovy-binary-2.5.2.zip' -GROOVY_DOWNLOAD_FILE="/tmp/~`basename "$GROOVY_DOWNLOAD_URL"`" - -GROOVY_DIR="/tmp/.groovy" -if [ ! -d "${GROOVY_DIR}" ] ; then - if [ ! -f "${GROOVY_DOWNLOAD_FILE}" ] ; then - info "Downloading Groovy" - curl -sL -o "${GROOVY_DOWNLOAD_FILE}" "${GROOVY_DOWNLOAD_URL}" +if [ ! -n "$GROOVYCMD" ] ; then + GROOVY_DOWNLOAD_URL='https://dl.bintray.com/groovy/maven/apache-groovy-binary-2.5.2.zip' + GROOVY_DOWNLOAD_FILE="/tmp/~`basename "$GROOVY_DOWNLOAD_URL"`" + GROOVY_DIR="/tmp/.groovy" + if [ ! -d "${GROOVY_DIR}" ] ; then + if [ ! -f "${GROOVY_DOWNLOAD_FILE}" ] ; then + info "Downloading Groovy" + curl -sL -o "${GROOVY_DOWNLOAD_FILE}" "${GROOVY_DOWNLOAD_URL}" + fi + info "Extracting Groovy" + mkdir -p "${GROOVY_DIR}" + unzip -oq "${GROOVY_DOWNLOAD_FILE}" -d "${GROOVY_DIR}" fi - info "Extracting Groovy" - mkdir -p "${GROOVY_DIR}" - unzip -oq "${GROOVY_DOWNLOAD_FILE}" -d "${GROOVY_DIR}" + #find "${GROOVY_DIR}/" -type f -name 'groovy' -perm +111 + GROOVYCMD="${GROOVY_DIR}/groovy-2.5.2/bin/groovy" fi -#find "${GROOVY_DIR}/" -type f -name 'groovy' -perm +111 -GROOVYCMD="${GROOVY_DIR}/groovy-2.5.2/bin/groovy" - -#echo "GROOVYCMD=${GROOVYCMD}" +export GROOVYCMD OCP_PIPELINE_VERSION="${OCP_PIPELINE_VERSION:-0.0.5}" OCP_PIPELINE_DOWNLOAD_URL="https://github.com/BCDevOps/ocp-cd-pipeline/archive/v${OCP_PIPELINE_VERSION}.zip" @@ -137,7 +137,13 @@ echo "OCP_PIPELINE_DIR=${OCP_PIPELINE_DIR}" echo "OCP_PIPELINE_LIB_DIR=${OCP_PIPELINE_LIB_DIR}" PIPELINE_STAGE="$1"; shift - PIPELINE_STAGE_SCRIPT="${OCP_PIPELINE_LIB_DIR}/example/${PIPELINE_STAGE}.groovy" +#Allow scripts to be locally provided/overwritten +if [ ! -z "$PIPELINE_LOCAL_STAGE_DIR" ]; then + if [ -f "${PIPELINE_LOCAL_STAGE_DIR}/${PIPELINE_STAGE}.groovy" ]; then + PIPELINE_STAGE_SCRIPT="${PIPELINE_LOCAL_STAGE_DIR}/${PIPELINE_STAGE}.groovy" + fi +fi + exec "${GROOVYCMD}" -cp "${OCP_PIPELINE_LIB_DIR}" "${PIPELINE_STAGE_SCRIPT}" "$@" \ No newline at end of file