[SEBA-497] v2

Fixes to the standalone docker-publish job

Change-Id: Ie89a15bd3b315e0fb31e58edb5059d9eb5d0ebc4
diff --git a/jjb/pipeline/docker-publish.groovy b/jjb/pipeline/docker-publish.groovy
index 89eef34..e9f05a3 100644
--- a/jjb/pipeline/docker-publish.groovy
+++ b/jjb/pipeline/docker-publish.groovy
@@ -13,7 +13,7 @@
           $class: 'GitSCM',
           userRemoteConfigs: [[
             url: "${params.gitUrl}",
-            name: "${params.GERRIT_PATCHSET_REVISION}",
+            name: "${params.gitRef}",
           ]],
           extensions: [
             [$class: 'WipeWorkspace'],
@@ -22,36 +22,41 @@
           ],
         ])
         script {
-          def git_tags={ shell "git tag -l --points-at HEAD" }
+          git_tags = sh(script:"cd $GERRIT_PROJECT; git tag -l --points-at HEAD", returnStdout: true).trim()
         }
       }
     }
 
     stage('build'){
       steps {
-        sh """
+        sh( script: """
           #!/usr/bin/env bash
           set -eu -o pipefail
 
           # checked out in a subdir so the log can be in WORKSPACE
           cd "$GERRIT_PROJECT"
 
+          # set registry/repository variables
+          export DOCKER_REGISTRY="$dockerRegistry"
           export DOCKER_REPOSITORY="$dockerRepo/"
 
           # Build w/branch
           echo "Building image with branch"
-          make DOCKER_TAG="$GERRIT_BRANCH" docker-build 2>&1 | tee > "$WORKSPACE/docker-build.log"
+          make DOCKER_TAG="$GERRIT_BRANCH" docker-build 2>&1 | tee "$WORKSPACE/docker-build.log"
 
           # Build w/tags if they exist
           if [ -n "$git_tags" ]
+          echo "Tags found in git, building:"
+          echo "$git_tags"
+
           then
             for tag in $git_tags
             do
-              echo "Building image with tag (should reuse cached layers)"
-              make DOCKER_TAG="$tag" docker-build
+              echo "Building image with tag: \$tag (should reuse cached layers)"
+              make DOCKER_TAG="\$tag" docker-build
             done
           fi
-        """
+        """)
       }
     }
 
@@ -59,29 +64,33 @@
       steps {
         script {
           withDockerRegistry([credentialsId: 'docker-artifact-push-credentials']) {
-            sh """
+            sh( script:"""
               #!/usr/bin/env bash
               set -eu -o pipefail
 
               # checked out in a subdir so the log can be in WORKSPACE
               cd "$GERRIT_PROJECT"
 
+              # set registry/repository variables
+              export DOCKER_REGISTRY="$dockerRegistry"
               export DOCKER_REPOSITORY="$dockerRepo/"
 
               # Push w/branch
               echo "Pushing image with branch"
-              make DOCKER_TAG="$GERRIT_BRANCH" docker-push 2>&1 | tee > "$WORKSPACE/docker-push.log"
+              make DOCKER_TAG="$GERRIT_BRANCH" docker-push 2>&1 | tee  "$WORKSPACE/docker-push.log"
 
               # Push w/tags if they exist
               if [ -n "$git_tags" ]
+              echo "Tags found in git, pushing:"
+              echo "$git_tags"
               then
                 for tag in $git_tags
                 do
-                  echo "Pushing image with tag (should reuse cached layers)"
-                  make DOCKER_TAG="$tag" docker-push
+                  echo "Pushing image with tag: \$tag (should reuse cached layers)"
+                  make DOCKER_TAG="\$tag" docker-push
                 done
               fi
-            """
+            """)
           }
         }
       }
@@ -90,7 +99,7 @@
 
   post {
     always {
-      archiveArtifacts artifacts: 'docker-build.log', fingerprint: true
+      archiveArtifacts artifacts: 'docker-*.log', fingerprint: true
       deleteDir()
     }
   }