Merge "Make slack less chatty"
[infra/cicd.git] / jjb / global / push-upstream-jobs.sh
index 12f0ab26945db8d14e097fdb6028f3d190b8680e..49af36e76eeb92801afa401140a22f080e236d9b 100755 (executable)
@@ -1,4 +1,4 @@
-#! /bin/bash
+#!/bin/bash
 
 # ============LICENSE_START=======================================================
 #  Copyright (C) 2019 The Nordix Foundation. All rights reserved.
 # - Author name in Nordix Gerrit equals LFID i.e. need to run "git config --global user.name <LFID>"
 # - infra public key on build server needs to be added to your users SSH Public Keys in ONAP Gerrit
 #
+set -o nounset
+set -o pipefail
 
 cd $WORKSPACE
-
+echo "Retrieving information from commit to push towards ONAP"
 project=$(git config --local remote.origin.url | awk -F "29418/" '{print $2}')
 message=$(git show -s --pretty=%B | grep -vi 'Signed-off-by')
 username=$(git show -s --pretty=%an)
@@ -38,24 +40,37 @@ then
     exit 1
 fi
 
+echo "Setting user name and email"
 git config user.email $(git show -s --pretty=%ae)
 git config user.name $username
 
-git reset HEAD~1
-git checkout -b delivery_branch origin/master
+echo "Checking out branch on master with new changes"
+git reset HEAD~1 --soft
+git checkout -b delivery_branch origin/$BRANCH
+
+git config --get remote.upstream.url
+retVal=$?
 
-echo '[remote "upstream"]' >> .git/config
-echo "  url = ssh://$username@gerrit.onap.org:29418/$project.git" >> .git/config
-echo "  fetch = +refs/heads/*:refs/remotes/upstream/*" >> .git/config
+if [[ $retVal -eq 0 ]]
+then
+  git remote rm upstream
+  git remote add upstream "ssh://$username@gerrit.onap.org:29418/$project.git"
+else
+  git remote add upstream "ssh://$username@gerrit.onap.org:29418/$project.git"
+fi
 
+echo "Committing changes and pushing upstream"
 git commit -as -m "$message"
+git push upstream HEAD:refs/for/$BRANCH
 
-git push upstream HEAD:refs/for/master
-retVal=$?
-if [[ $retVal -eq 0 ]]
+retVal1=$?
+if [[ $retVal1 -eq 0 ]]
 then
   echo "Push upstream to ONAP succeeded"
 else
   echo "Push upstream to ONAP failed"
   exit 2
 fi
+
+git checkout $BRANCH
+git branch -D delivery_branch