Add DRY_RUN param to the release job
[releng/global-jjb.git] / shell / release-job.sh
index 31721d1..fd43d75 100644 (file)
@@ -51,7 +51,7 @@ tag(){
     echo "git tag -v $VERSION"
     git tag -v "$VERSION"
     ########## Merge Part ##############
-    if [[ "$JOB_NAME" =~ "merge" ]]; then
+    if [[ "$JOB_NAME" =~ "merge" ]] && [[ "$DRY_RUN" = false ]]; then
       echo "--> INFO: Running merge"
       gerrit_ssh=$(echo "$GERRIT_URL" | awk -F"/" '{print $3}')
       git remote set-url origin ssh://"$RELEASE_USERNAME"@"$gerrit_ssh":29418/"$PROJECT"
@@ -75,16 +75,60 @@ nexus_release(){
     lftools nexus release -v --server https://"$NEXUS_URL" "$STAGING_REPO"
     echo "Merge will run"
     echo "lftools nexus release --server https://$NEXUS_URL $STAGING_REPO"
-    if [[ "$JOB_NAME" =~ "merge" ]]; then
+  done
+
+  #Run the loop twice, to catch errors on either nexus repo
+  if [[ "$JOB_NAME" =~ "merge" ]] && [[ "$DRY_RUN" = false ]]; then
+    for staging_url in $(zcat "$PATCH_DIR"/staging-repo.txt.gz | awk -e '{print $2}'); do
+      NEXUS_URL=$(echo "$staging_url" | sed -e 's|^[^/]*//||' -e 's|/.*$||')
+      STAGING_REPO=${staging_url#*repositories/}
       echo "Promoting $STAGING_REPO on $NEXUS_URL."
       lftools nexus release --server https://"$NEXUS_URL" "$STAGING_REPO"
-    fi
-  done
+    done
+  fi
 }
 
+
 container_release_file(){
   echo "---> Processing container release"
-  # Container-release code is addressed in a new feature patchset.
+  local lfn_umbrella
+  lfn_umbrella="$(echo "$GERRIT_HOST" | awk -F"." '{print $2}')"
+
+
+  for namequoted in $(cat $release_file | yq '.containers[].name'); do
+    versionquoted=$(cat $release_file | yq ".containers[] |select(.name=="$namequoted") |.version")
+
+    #Remove extra yaml quotes
+    name="${namequoted#\"}"
+    name="${name%\"}"
+    version="${versionquoted#\"}"
+    version="${version%\"}"
+
+    echo "$name"
+    echo "$version"
+    echo "---> INFO: Merge will release $name $version as $VERSION"
+    #Pull from public, to see if we have already tagged this.
+    if docker pull "$DOCKER_REGISTRY":10002/"$lfn_umbrella"/"$name":"$VERSION"; then
+      echo "---> OK: $VERSION is already released for image $name, Continuing..."
+    else
+      echo "---> OK: $VERSION not found in releases, release will be prepared. Continuing..."
+      docker pull "$DOCKER_REGISTRY":10001/"$lfn_umbrella"/"$name":"$version"
+      container_image_id="$(docker images | grep $name | grep $version | awk '{print $3}')"
+      echo "---> INFO: Merge will run the following commands:"
+      echo "docker tag $container_image_id $DOCKER_REGISTRY:10002/$lfn_umbrella/$name:$VERSION"
+      echo "docker push $DOCKER_REGISTRY:10002/$lfn_umbrella/$name:$VERSION"
+      if [[ "$JOB_NAME" =~ "merge" ]]; then
+        docker tag "$container_image_id" "$DOCKER_REGISTRY":10002/"$lfn_umbrella"/"$name":"$VERSION"
+        docker push "$DOCKER_REGISTRY":10002/"$lfn_umbrella"/"$name":"$VERSION"
+      fi
+      echo "#########################"
+    fi
+  done
+
+  ref="$(niet ".ref" "$release_file")"
+  echo "---> INFO: Merge will tag ref: $ref"
+  git checkout "$ref"
+  tag
 }
 
 maven_release_file(){
@@ -113,8 +157,7 @@ if [ "${LOGS_SERVER}" == 'None' ]; then
     exit 1
 fi
 
-RELEASE_FILE="${RELEASE_FILE:-True}"
-if [[ "$RELEASE_FILE" == "True" ]]; then
+if $USE_RELEASE_FILE ; then
 
   release_files=$(git diff-tree --no-commit-id -r "$GERRIT_PATCHSET_REVISION" --name-only -- "releases/" ".releases/")
   if (( $(grep -c . <<<"$release_files") > 1 )); then
@@ -127,7 +170,7 @@ if [[ "$RELEASE_FILE" == "True" ]]; then
   fi
 
 else
-  echo "This is job is built with parameters, no release file needed"
+  echo "This job is built with parameters, no release file needed. Continuing..."
   release_file="None"
 fi
 
@@ -173,12 +216,14 @@ echo "DISTRIBUTION_TYPE: $DISTRIBUTION_TYPE"
 if [[ "$DISTRIBUTION_TYPE" == "maven" ]]; then
   wget -q https://raw.githubusercontent.com/lfit/releng-global-jjb/master/schema/release-schema.yaml
   RELEASE_SCHEMA="release-schema.yaml"
-  if [[ "$RELEASE_FILE" == "True" ]]; then
+  if $USE_RELEASE_FILE ; then
     verify_schema
   fi
   maven_release_file
 elif [[ "$DISTRIBUTION_TYPE" == "container" ]]; then
-  # Container-release code is addressed in a new feature patchset.
+  wget -q https://raw.githubusercontent.com/lfit/releng-global-jjb/master/schema/release-container-schema.yaml
+  RELEASE_SCHEMA="release-container-schema.yaml"
+  verify_schema
   container_release_file
 else
   echo "---> ERROR: distribution_type: $DISTRIBUTION_TYPE not supported"
@@ -188,4 +233,3 @@ fi
 ##########################################
 
 echo "########### End Script release-job.sh ###################################"
-