ACUMOS: Improve jenkins jobs for Acumos projects

- Mirror branches from Acumos upstream project to Nordix.
- Do not force the git user.name to be the gerrit id.
  Git authorship can be independent from the
  gerrit review ownership now.
- Cache the repository on the Jenkins slave nodes
  when rebasing repositories.
- Make sure the commit hash in the local repo is the same
  as in nordix Gerrit and the same as the commit hash
  in the upstream gerrit.
- Decrease number of jobs required for project in Jenkins

Change-Id: I29ea8b9b2573b5d894246f47b537aeb61027f6f8
diff --git a/jjb/acumos/acumos-java-client/acumos-java-client-push-upstream-jobs.yml b/jjb/acumos/acumos-java-client/acumos-java-client-push-upstream-jobs.yml
index 36b9c03..297cfae 100644
--- a/jjb/acumos/acumos-java-client/acumos-java-client-push-upstream-jobs.yml
+++ b/jjb/acumos/acumos-java-client/acumos-java-client-push-upstream-jobs.yml
@@ -21,9 +21,6 @@
     name: acumos-java-client-push-upstream
     project: acumos-java-client
     project-name: acumos-java-client
-    stream:
-      - master:
-          branch: '{stream}'
 
     jobs:
-      - 'acumos-{project-name}-{stream}-push-upstream'
+      - 'acumos-{project-name}-push-upstream'
diff --git a/jjb/acumos/acumos-java-client/acumos-java-client-rebase-jobs.yml b/jjb/acumos/acumos-java-client/acumos-java-client-rebase-jobs.yml
index a297e48..c0eefe3 100644
--- a/jjb/acumos/acumos-java-client/acumos-java-client-rebase-jobs.yml
+++ b/jjb/acumos/acumos-java-client/acumos-java-client-rebase-jobs.yml
@@ -21,9 +21,6 @@
     name: acumos-java-client-rebase
     project: acumos-java-client
     project-name: acumos-java-client
-    stream:
-      - master:
-          branch: '{stream}'
 
     jobs:
-      - 'acumos-{project-name}-{stream}-rebase'
+      - 'acumos-{project-name}-rebase'
diff --git a/jjb/acumos/acumos-java-client/acumos-java-client-verify-jobs.yaml b/jjb/acumos/acumos-java-client/acumos-java-client-verify-jobs.yaml
index b2b23ce..1cd317d 100644
--- a/jjb/acumos/acumos-java-client/acumos-java-client-verify-jobs.yaml
+++ b/jjb/acumos/acumos-java-client/acumos-java-client-verify-jobs.yaml
@@ -21,9 +21,6 @@
     name: acumos-java-client-verify
     project: acumos-java-client
     project-name: acumos-java-client
-    stream:
-      - master:
-          branch: '{stream}'
 
     jobs:
-      - 'acumos-{project-name}-{stream}-verify-java'
+      - 'acumos-{project-name}-verify-java'
diff --git a/jjb/acumos/face-privacy-filter/face-privacy-filter-push-upstream-jobs.yml b/jjb/acumos/face-privacy-filter/face-privacy-filter-push-upstream-jobs.yml
index 49d02e1..fcabea5 100644
--- a/jjb/acumos/face-privacy-filter/face-privacy-filter-push-upstream-jobs.yml
+++ b/jjb/acumos/face-privacy-filter/face-privacy-filter-push-upstream-jobs.yml
@@ -21,9 +21,6 @@
     name: face-privacy-filter-push-upstream
     project: face-privacy-filter
     project-name: face-privacy-filter
-    stream:
-      - master:
-          branch: '{stream}'
 
     jobs:
-      - 'acumos-{project-name}-{stream}-push-upstream'
+      - 'acumos-{project-name}-push-upstream'
diff --git a/jjb/acumos/face-privacy-filter/face-privacy-filter-rebase-jobs.yml b/jjb/acumos/face-privacy-filter/face-privacy-filter-rebase-jobs.yml
index 7bca15c..601ccca 100644
--- a/jjb/acumos/face-privacy-filter/face-privacy-filter-rebase-jobs.yml
+++ b/jjb/acumos/face-privacy-filter/face-privacy-filter-rebase-jobs.yml
@@ -21,9 +21,6 @@
     name: face-privacy-filter-rebase
     project: face-privacy-filter
     project-name: face-privacy-filter
-    stream:
-      - master:
-          branch: '{stream}'
 
     jobs:
-      - 'acumos-{project-name}-{stream}-rebase'
+      - 'acumos-{project-name}-rebase'
diff --git a/jjb/acumos/federation/federation-push-upstream-jobs.yml b/jjb/acumos/federation/federation-push-upstream-jobs.yml
index 494c077..acdb9ed 100644
--- a/jjb/acumos/federation/federation-push-upstream-jobs.yml
+++ b/jjb/acumos/federation/federation-push-upstream-jobs.yml
@@ -22,9 +22,5 @@
     project: federation
     project-name: federation
 
-    stream:
-      - master:
-          branch: '{stream}'
-
     jobs:
-      - 'acumos-{project-name}-{stream}-push-upstream'
+      - 'acumos-{project-name}-push-upstream'
diff --git a/jjb/acumos/federation/federation-rebase-jobs.yml b/jjb/acumos/federation/federation-rebase-jobs.yml
index 7748dc2..845064a 100644
--- a/jjb/acumos/federation/federation-rebase-jobs.yml
+++ b/jjb/acumos/federation/federation-rebase-jobs.yml
@@ -21,8 +21,6 @@
     name: federation-rebase
     project: federation
     project-name: federation
-    stream:
-      - master:
-          branch: '{stream}'
+
     jobs:
-      - 'acumos-{project-name}-{stream}-rebase'
+      - 'acumos-{project-name}-rebase'
diff --git a/jjb/acumos/federation/federation-verify-jobs.yml b/jjb/acumos/federation/federation-verify-jobs.yml
index cfd4e99..74c7af0 100644
--- a/jjb/acumos/federation/federation-verify-jobs.yml
+++ b/jjb/acumos/federation/federation-verify-jobs.yml
@@ -22,9 +22,5 @@
     project: federation
     project-name: federation
 
-    stream:
-      - master:
-          branch: '{stream}'
-
     jobs:
-      - 'acumos-{project-name}-{stream}-verify-java'
+      - 'acumos-{project-name}-verify-java'
diff --git a/jjb/acumos/global-templates-acumos-java.yaml b/jjb/acumos/global-templates-acumos-java.yaml
index 707f398..2ea9d53 100644
--- a/jjb/acumos/global-templates-acumos-java.yaml
+++ b/jjb/acumos/global-templates-acumos-java.yaml
@@ -1,5 +1,5 @@
 - job-template:
-    name: 'acumos-{project-name}-{stream}-verify-java'
+    name: 'acumos-{project-name}-verify-java'
 
     node: acumos-ubuntu1604
 
@@ -11,11 +11,12 @@
       - logrotate
 
     parameters:
-      - project-parameters:
-          project: 'acumos/{project}'
-          branch: '{branch}'
       - nordix-gerrit-parameters
       - string:
+          name: PROJECT
+          default: 'acumos/{project}'
+          description: JJB configured PROJECT parameter to identify a Nordix Gerrit project
+      - string:
           name: JAVA_HOME
           default: /usr/lib/jvm/java-1.8.0-openjdk-amd64
           description: Java home
@@ -35,7 +36,7 @@
     scm:
       - git-scm-gerrit:
           ssh-credentials-id: nordixinfra-nordix-gerrit-ssh
-          branch: '{branch}'
+          branch: $GERRIT_BRANCH
           refspec: $GERRIT_REFSPEC
           wipe_workspace: true
           clean_before: false
@@ -43,7 +44,7 @@
     triggers:
       - nordix-gerrit-trigger-patchset-created:
           project: 'acumos/{project}'
-          branch: '{branch}'
+          branch: '**'
           files: '**'
 
     wrappers:
diff --git a/jjb/acumos/global-templates-acumos-push-upstream.yaml b/jjb/acumos/global-templates-acumos-push-upstream.yaml
index 2a31aaf..a0cf5b1 100644
--- a/jjb/acumos/global-templates-acumos-push-upstream.yaml
+++ b/jjb/acumos/global-templates-acumos-push-upstream.yaml
@@ -1,7 +1,7 @@
 - job-template:
-    name: 'acumos-{project-name}-{stream}-push-upstream'
+    name: 'acumos-{project-name}-push-upstream'
 
-    node: onap-ubuntu1604
+    node: infra-build01-ubuntu1804
 
     disabled: false
 
@@ -11,15 +11,16 @@
       - logrotate
 
     parameters:
-      - project-parameters:
-          project: 'acumos/{project}'
-          branch: '{branch}'
+      - string:
+          name: PROJECT
+          default: 'acumos/{project}'
+          description: JJB configured PROJECT parameter to identify a Nordix Gerrit project
       - nordix-gerrit-parameters
 
     scm:
       - git-scm-gerrit:
           ssh-credentials-id: nordixinfra-nordix-gerrit-ssh
-          branch: '{branch}'
+          branch: $GERRIT_BRANCH
           refspec: $GERRIT_REFSPEC
           wipe_workspace: true
           clean_before: false
@@ -27,7 +28,7 @@
     triggers:
       - nordix-gerrit-push-upstream:
           project: 'acumos/{project}'
-          branch: '{branch}'
+          branch: '**'
           files: '**'
 
     wrappers:
diff --git a/jjb/acumos/global-templates-acumos-rebase.yaml b/jjb/acumos/global-templates-acumos-rebase.yaml
index 994c923..1a25eb3 100644
--- a/jjb/acumos/global-templates-acumos-rebase.yaml
+++ b/jjb/acumos/global-templates-acumos-rebase.yaml
@@ -1,5 +1,5 @@
 - job-template:
-    name: 'acumos-{project-name}-{stream}-rebase'
+    name: 'acumos-{project-name}-rebase'
 
     node: infra-build01-ubuntu1804
 
@@ -11,11 +11,12 @@
       - logrotate
 
     parameters:
-      - project-parameters:
-          project: '{project}'
-          branch: '{branch}'
       - acumos-gerrit-parameters
       - string:
+          name: PROJECT
+          default: '{project}'
+          description: JJB configured PROJECT parameter to identify a Nordix Gerrit project
+      - string:
           name: NORDIX_REMOTE
           default: 'ssh://infra@gerrit.nordix.org:29418/acumos/{project}.git'
           description: The remote to add for Nordix.
@@ -23,15 +24,15 @@
     scm:
       - git-scm:
           ssh-credentials-id: nordixinfra-lfn-gerrit-ssh
-          branch: '{branch}'
+          branch: 'master'
           refspec: ''
-          wipe_workspace: true
-          clean_before: false
+          wipe_workspace: false
+          clean_before: true
 
     triggers:
       - acumos-gerrit-trigger-change-merged:
           project: '{project}'
-          branch: '{branch}'
+          branch: '**'
           files: '**'
       - timed: "@midnight"
 
@@ -41,8 +42,8 @@
 
     builders:
       - shell:
-          !include-raw-escape: ../global/rebase-jobs.sh
+          !include-raw-escape: ./rebase-jobs.sh
 
     publishers:
       - notify-slack:
-          slack-channel: '#acumos'
+          slack-channel: '#infra'
diff --git a/jjb/acumos/kubernetes-client/kubernetes-client-push-upstream-jobs.yml b/jjb/acumos/kubernetes-client/kubernetes-client-push-upstream-jobs.yml
index 7b1cf16..3566a49 100644
--- a/jjb/acumos/kubernetes-client/kubernetes-client-push-upstream-jobs.yml
+++ b/jjb/acumos/kubernetes-client/kubernetes-client-push-upstream-jobs.yml
@@ -22,9 +22,5 @@
     project: kubernetes-client
     project-name: kubernetes-client
 
-    stream:
-      - master:
-          branch: '{stream}'
-
     jobs:
-      - 'acumos-{project-name}-{stream}-push-upstream'
+      - 'acumos-{project-name}-push-upstream'
diff --git a/jjb/acumos/kubernetes-client/kubernetes-client-rebase-jobs.yml b/jjb/acumos/kubernetes-client/kubernetes-client-rebase-jobs.yml
index 11c6d10..a98f5c0 100644
--- a/jjb/acumos/kubernetes-client/kubernetes-client-rebase-jobs.yml
+++ b/jjb/acumos/kubernetes-client/kubernetes-client-rebase-jobs.yml
@@ -21,8 +21,6 @@
     name: kubernetes-client-rebase
     project: kubernetes-client
     project-name: kubernetes-client
-    stream:
-      - master:
-          branch: '{stream}'
+
     jobs:
-      - 'acumos-{project-name}-{stream}-rebase'
+      - 'acumos-{project-name}-rebase'
diff --git a/jjb/acumos/kubernetes-client/kubernetes-client-verify-jobs.yaml b/jjb/acumos/kubernetes-client/kubernetes-client-verify-jobs.yaml
index 48c7130..4d0708b 100644
--- a/jjb/acumos/kubernetes-client/kubernetes-client-verify-jobs.yaml
+++ b/jjb/acumos/kubernetes-client/kubernetes-client-verify-jobs.yaml
@@ -22,9 +22,5 @@
     project: kubernetes-client
     project-name: kubernetes-client
 
-    stream:
-      - master:
-          branch: '{stream}'
-
     jobs:
-      - 'acumos-{project-name}-{stream}-verify-java'
+      - 'acumos-{project-name}-verify-java'
diff --git a/jjb/acumos/license-manager/license-manager-push-upstream-jobs.yml b/jjb/acumos/license-manager/license-manager-push-upstream-jobs.yml
index abf1c7b..f10472c 100644
--- a/jjb/acumos/license-manager/license-manager-push-upstream-jobs.yml
+++ b/jjb/acumos/license-manager/license-manager-push-upstream-jobs.yml
@@ -22,9 +22,5 @@
     project: license-manager
     project-name: license-manager
 
-    stream:
-      - master:
-          branch: '{stream}'
-
     jobs:
-      - 'acumos-{project-name}-{stream}-push-upstream'
+      - 'acumos-{project-name}-push-upstream'
diff --git a/jjb/acumos/license-manager/license-manager-rebase-jobs.yml b/jjb/acumos/license-manager/license-manager-rebase-jobs.yml
index ba0f4bf..89968e3 100644
--- a/jjb/acumos/license-manager/license-manager-rebase-jobs.yml
+++ b/jjb/acumos/license-manager/license-manager-rebase-jobs.yml
@@ -21,8 +21,6 @@
     name: license-manager-rebase
     project: license-manager
     project-name: license-manager
-    stream:
-      - master:
-          branch: '{stream}'
+
     jobs:
-      - 'acumos-{project-name}-{stream}-rebase'
+      - 'acumos-{project-name}-rebase'
diff --git a/jjb/acumos/license-manager/license-manager-verify-jobs.yaml b/jjb/acumos/license-manager/license-manager-verify-jobs.yaml
index 1189c4c..110f4d3 100644
--- a/jjb/acumos/license-manager/license-manager-verify-jobs.yaml
+++ b/jjb/acumos/license-manager/license-manager-verify-jobs.yaml
@@ -22,9 +22,5 @@
     project: license-manager
     project-name: license-manager
 
-    stream:
-      - master:
-          branch: '{stream}'
-
     jobs:
-      - 'acumos-{project-name}-{stream}-verify-java'
+      - 'acumos-{project-name}-verify-java'
diff --git a/jjb/acumos/microservice-generation/microservice-generation-push-upstream-jobs.yml b/jjb/acumos/microservice-generation/microservice-generation-push-upstream-jobs.yml
index ed85e80..7357a0e 100644
--- a/jjb/acumos/microservice-generation/microservice-generation-push-upstream-jobs.yml
+++ b/jjb/acumos/microservice-generation/microservice-generation-push-upstream-jobs.yml
@@ -22,9 +22,5 @@
     project: microservice-generation
     project-name: microservice-generation
 
-    stream:
-      - master:
-          branch: '{stream}'
-
     jobs:
-      - 'acumos-{project-name}-{stream}-push-upstream'
+      - 'acumos-{project-name}-push-upstream'
diff --git a/jjb/acumos/microservice-generation/microservice-generation-rebase-jobs.yml b/jjb/acumos/microservice-generation/microservice-generation-rebase-jobs.yml
index 47ee772..1d1e61c 100644
--- a/jjb/acumos/microservice-generation/microservice-generation-rebase-jobs.yml
+++ b/jjb/acumos/microservice-generation/microservice-generation-rebase-jobs.yml
@@ -21,8 +21,6 @@
     name: microservice-generation-rebase
     project: microservice-generation
     project-name: microservice-generation
-    stream:
-      - master:
-          branch: '{stream}'
+
     jobs:
-      - 'acumos-{project-name}-{stream}-rebase'
+      - 'acumos-{project-name}-rebase'
diff --git a/jjb/acumos/microservice-generation/microservice-generation-verify-jobs.yaml b/jjb/acumos/microservice-generation/microservice-generation-verify-jobs.yaml
index 4b996f0..c0cc9b7 100644
--- a/jjb/acumos/microservice-generation/microservice-generation-verify-jobs.yaml
+++ b/jjb/acumos/microservice-generation/microservice-generation-verify-jobs.yaml
@@ -22,9 +22,5 @@
     project: microservice-generation
     project-name: microservice-generation
 
-    stream:
-      - master:
-          branch: '{stream}'
-
     jobs:
-      - 'acumos-{project-name}-{stream}-verify-java'
+      - 'acumos-{project-name}-verify-java'
diff --git a/jjb/acumos/portal-marketplace/portal-marketplace-push-upstream-jobs.yml b/jjb/acumos/portal-marketplace/portal-marketplace-push-upstream-jobs.yml
index 85b1257..f119287 100644
--- a/jjb/acumos/portal-marketplace/portal-marketplace-push-upstream-jobs.yml
+++ b/jjb/acumos/portal-marketplace/portal-marketplace-push-upstream-jobs.yml
@@ -22,9 +22,5 @@
     project: portal-marketplace
     project-name: portal-marketplace
 
-    stream:
-      - master:
-          branch: '{stream}'
-
     jobs:
-      - 'acumos-{project-name}-{stream}-push-upstream'
+      - 'acumos-{project-name}-push-upstream'
diff --git a/jjb/acumos/portal-marketplace/portal-marketplace-rebase-jobs.yml b/jjb/acumos/portal-marketplace/portal-marketplace-rebase-jobs.yml
index 00fffea..ee384c8 100644
--- a/jjb/acumos/portal-marketplace/portal-marketplace-rebase-jobs.yml
+++ b/jjb/acumos/portal-marketplace/portal-marketplace-rebase-jobs.yml
@@ -21,8 +21,6 @@
     name: portal-marketplace-rebase
     project: portal-marketplace
     project-name: portal-marketplace
-    stream:
-      - master:
-          branch: '{stream}'
+
     jobs:
-      - 'acumos-{project-name}-{stream}-rebase'
+      - 'acumos-{project-name}-rebase'
diff --git a/jjb/acumos/portal-marketplace/portal-marketplace-verify-jobs.yaml b/jjb/acumos/portal-marketplace/portal-marketplace-verify-jobs.yaml
index f48fe83..e8c03f5 100644
--- a/jjb/acumos/portal-marketplace/portal-marketplace-verify-jobs.yaml
+++ b/jjb/acumos/portal-marketplace/portal-marketplace-verify-jobs.yaml
@@ -22,9 +22,5 @@
     project: portal-marketplace
     project-name: portal-marketplace
 
-    stream:
-      - master:
-          branch: '{stream}'
-
     jobs:
-      - 'acumos-{project-name}-{stream}-verify-java'
+      - 'acumos-{project-name}-verify-java'
diff --git a/jjb/acumos/push-upstream-jobs.sh b/jjb/acumos/push-upstream-jobs.sh
index 1eded15..9354bfb 100755
--- a/jjb/acumos/push-upstream-jobs.sh
+++ b/jjb/acumos/push-upstream-jobs.sh
@@ -19,58 +19,62 @@
 # ============LICENSE_END=========================================================
 
 #
-# This script will take the changes that are pushed to Nordix Gerrit and push upstream to ONAP
+# This script will take the single commit form the given Nordix Gerrit review
+# and push it, and all its ancestor commit till $GERRIT_BRANCH, to Acumos
+# Gerrit.
 # Pre-requisites for script to run successfully:
-# - 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
+# - The Gerrit username in Nordix needs to match with the Gerrit username in
+#   Acumos
+# - infra public key on build server needs to be added to your users SSH
+#   Public Keys in Acumos Gerrit
 #
-set -o nounset
-set -o pipefail
+set -euxo pipefail
 
-cd $WORKSPACE
-echo "Retrieving information from commit to push towards Acumos"
-project=$(git config --local remote.origin.url | awk -F "29418/acumos/" '{print $2}')
-message=$(git show -s --pretty=%B | grep -vi 'Signed-off-by')
-username=$(git show -s --pretty=%an)
+cd "$WORKSPACE"
 
-pattern=" "
-if [[ "$username" =~ $pattern ]]
-then
-    echo "Incorrect username, use Linux Foundation ID as git user.name when pushing to Nordix"
-    exit 1
-fi
+acumos_gerrit_base='gerrit.acumos.org:29418'
+nordix_gerrit_rest='https://gerrit.nordix.org'
 
-echo "Setting user name and email"
-git config user.email $(git show -s --pretty=%ae)
-git config user.name $username
+echo >&2 "Collecting information about what and how to push towards Acumos"
 
-echo "Checking out branch on master with new changes"
-git reset HEAD~1 --soft
-git checkout -b delivery_branch origin/$BRANCH
+# The git hash of the commit in the review this job runs on
+commit_hash="$GERRIT_PATCHSET_REVISION"
 
-git config --get remote.upstream.url
-retVal=$?
+# GERRIT_PROJECT is in the form of acumos/<acumos-project>
+acumos_project=$(echo "$GERRIT_PROJECT" | cut -d/ -f2- )
 
-if [[ $retVal -eq 0 ]]
-then
-  git remote rm upstream
-  git remote add upstream "ssh://$username@gerrit.acumos.org:29418/$project.git"
+# Nordix Gerrit can map the email address of the user pushed the change to
+# the review to the Gerrit username of the account in Nordix Gerrit. This
+# should match with the Gerrit username in the Acumos Gerrit.
+username=$(
+    curl -s -H 'Accept: application/json' \
+        "$nordix_gerrit_rest/accounts/?q=email:$GERRIT_EVENT_ACCOUNT_EMAIL&o=DETAILS" \
+    | tee /dev/stderr | tail -1 | jq -r '.[0].username')
+
+acumos_remote_url="ssh://$username@$acumos_gerrit_base/$acumos_project"
+
+# GERRIT_BRANCH is the _intended_ branch of the commit under review
+# E.g. git push HEAD:refs/for/master => GERRIT_BRANCH='master'
+# GERRIT_TOPIC is the rest of the refspec after GERRIT_BRANCH when the topic
+# is set for the change.
+if [ -z "${GERRIT_TOPIC:-}" ] ; then
+    refspec="$commit_hash:refs/for/$GERRIT_BRANCH"
 else
-  git remote add upstream "ssh://$username@gerrit.acumos.org:29418/$project.git"
+    refspec="$commit_hash:refs/for/$GERRIT_BRANCH/$GERRIT_TOPIC"
 fi
 
-echo "Committing changes and pushing upstream"
-git commit -as -m "$message"
-git push upstream HEAD:refs/for/$BRANCH
+echo >&2 "Pushing to Acumos"
 
-retVal1=$?
-if [[ $retVal1 -eq 0 ]]
-then
-  echo "Push upstream to Acumos succeeded"
-else
-  echo "Push upstream to Acumos failed"
-  exit 2
+# do not fail if git push fails as in case of no new changes we want to succeed. See below.
+set +o pipefail
+
+git push "$acumos_remote_url" "$refspec" 2>&1 | tee push_result.txt
+push_result=${PIPESTATUS[0]}
+
+# make the job a success if the above git push fails due to no new changes are needed
+# to be created upstream. This will be useful when we switch to automatic triggering
+# of the push-upstream for each patch set and jobs on different commits in a same chain
+# will race with each other to push parts of the chain
+if [ $push_result -ne 0 ]; then
+    grep '(no new changes)' push_result.txt
 fi
-
-git checkout $BRANCH
-git branch -D delivery_branch
diff --git a/jjb/acumos/rebase-jobs.sh b/jjb/acumos/rebase-jobs.sh
new file mode 100755
index 0000000..41c2aa3
--- /dev/null
+++ b/jjb/acumos/rebase-jobs.sh
@@ -0,0 +1,40 @@
+#!/bin/bash
+set -o errexit
+set -o nounset
+set -o pipefail
+
+cd $WORKSPACE
+# Make sure the Nordix is set from Jenkins Job configuration
+# parameter: NORDIX_REMOTE and not from previous job execution
+if git remote | grep nordix > /dev/null ; then
+    git remote rm nordix
+fi
+# When the GERRIT_BRANCH is not set the rebase job wasn't triggered by merge
+# but it's executed as part of timer. In this case we will make sure that all
+# branches from remote are synced with Nordix Gerrit.
+if [[ -z "${GERRIT_BRANCH:-}" ]] ; then
+    echo "-- Fetch all branches from Acumos for project: ${PROJECT} --"
+    REMOTE_BRANCHES=$(git branch -r | grep -v 'HEAD -> ' | awk '/origin/ {gsub("origin/","");print}')
+    for branch in ${REMOTE_BRANCHES}  ; do
+        git branch -f --track ${branch} origin/${branch}
+    done
+# The job was triggered by merge on Acumos. We will make sure that branch set
+# in GERRIT_BRANCH is in sync with Nordix Gerrit.
+else
+    echo "-- Fetch branch: ${GERRIT_BRANCH} from Acumos for project: ${PROJECT} --"
+    REMOTE_BRANCHES=${GERRIT_BRANCH}
+    git branch -f --track ${GERRIT_BRANCH} origin/${GERRIT_BRANCH}
+fi
+git fetch origin -v
+echo "-- Adding new remote $NORDIX_REMOTE for sync --"
+git remote add nordix $NORDIX_REMOTE
+git remote -v
+echo "-- Merging changes from Acumos remote branches to local branch: --"
+for branch in ${REMOTE_BRANCHES}  ; do
+    echo "------ Branch name: ${branch}"
+    git checkout ${branch} -q
+    git merge origin/${branch} --ff-only --stat
+done
+echo "-- Pushing changes to Nordix Gerrit --"
+git push nordix --all -v
+echo "--------------------------------------------------------------------"
diff --git a/jjb/acumos/runtime-orchestrator/runtime-orchestrator-push-upstream-jobs.yml b/jjb/acumos/runtime-orchestrator/runtime-orchestrator-push-upstream-jobs.yml
index f207bcc..99dfe1f 100644
--- a/jjb/acumos/runtime-orchestrator/runtime-orchestrator-push-upstream-jobs.yml
+++ b/jjb/acumos/runtime-orchestrator/runtime-orchestrator-push-upstream-jobs.yml
@@ -22,9 +22,5 @@
     project: runtime-orchestrator
     project-name: runtime-orchestrator
 
-    stream:
-      - master:
-          branch: '{stream}'
-
     jobs:
-      - 'acumos-{project-name}-{stream}-push-upstream'
+      - 'acumos-{project-name}-push-upstream'
diff --git a/jjb/acumos/runtime-orchestrator/runtime-orchestrator-rebase-jobs.yml b/jjb/acumos/runtime-orchestrator/runtime-orchestrator-rebase-jobs.yml
index 34a4de5..28ef648 100644
--- a/jjb/acumos/runtime-orchestrator/runtime-orchestrator-rebase-jobs.yml
+++ b/jjb/acumos/runtime-orchestrator/runtime-orchestrator-rebase-jobs.yml
@@ -21,8 +21,6 @@
     name: runtime-orchestrator-rebase
     project: runtime-orchestrator
     project-name: runtime-orchestrator
-    stream:
-      - master:
-          branch: '{stream}'
+
     jobs:
-      - 'acumos-{project-name}-{stream}-rebase'
+      - 'acumos-{project-name}-rebase'
diff --git a/jjb/acumos/runtime-orchestrator/runtime-orchestrator-verify-jobs.yaml b/jjb/acumos/runtime-orchestrator/runtime-orchestrator-verify-jobs.yaml
index e874e5c..e82ff88 100644
--- a/jjb/acumos/runtime-orchestrator/runtime-orchestrator-verify-jobs.yaml
+++ b/jjb/acumos/runtime-orchestrator/runtime-orchestrator-verify-jobs.yaml
@@ -22,9 +22,5 @@
     project: runtime-orchestrator
     project-name: runtime-orchestrator
 
-    stream:
-      - master:
-          branch: '{stream}'
-
     jobs:
-      - 'acumos-{project-name}-{stream}-verify-java'
+      - 'acumos-{project-name}-verify-java'
diff --git a/jjb/acumos/security-verification/security-verification-push-upstream-jobs.yaml b/jjb/acumos/security-verification/security-verification-push-upstream-jobs.yaml
index 4a0193d..8b6a7a6 100644
--- a/jjb/acumos/security-verification/security-verification-push-upstream-jobs.yaml
+++ b/jjb/acumos/security-verification/security-verification-push-upstream-jobs.yaml
@@ -22,9 +22,5 @@
     project: security-verification
     project-name: security-verification
 
-    stream:
-      - master:
-          branch: '{stream}'
-
     jobs:
-      - 'acumos-{project-name}-{stream}-push-upstream'
+      - 'acumos-{project-name}-push-upstream'
diff --git a/jjb/acumos/security-verification/security-verification-rebase-jobs.yaml b/jjb/acumos/security-verification/security-verification-rebase-jobs.yaml
index 81aeed8..900ae0e 100644
--- a/jjb/acumos/security-verification/security-verification-rebase-jobs.yaml
+++ b/jjb/acumos/security-verification/security-verification-rebase-jobs.yaml
@@ -21,8 +21,6 @@
     name: security-verification-rebase
     project: security-verification
     project-name: security-verification
-    stream:
-      - master:
-          branch: '{stream}'
+
     jobs:
-      - 'acumos-{project-name}-{stream}-rebase'
+      - 'acumos-{project-name}-rebase'
diff --git a/jjb/acumos/security-verification/security-verification-verify-jobs.yaml b/jjb/acumos/security-verification/security-verification-verify-jobs.yaml
index 1cf609d..7138d98 100644
--- a/jjb/acumos/security-verification/security-verification-verify-jobs.yaml
+++ b/jjb/acumos/security-verification/security-verification-verify-jobs.yaml
@@ -22,9 +22,5 @@
     project: security-verification
     project-name: security-verification
 
-    stream:
-      - master:
-          branch: '{stream}'
-
     jobs:
-      - 'acumos-{project-name}-{stream}-verify-java'
+      - 'acumos-{project-name}-verify-java'
diff --git a/jjb/acumos/system-integration/system-integration-push-upstream-jobs.yml b/jjb/acumos/system-integration/system-integration-push-upstream-jobs.yml
index 7b45b44..585ca9d 100644
--- a/jjb/acumos/system-integration/system-integration-push-upstream-jobs.yml
+++ b/jjb/acumos/system-integration/system-integration-push-upstream-jobs.yml
@@ -22,9 +22,5 @@
     project: system-integration
     project-name: system-integration
 
-    stream:
-      - master:
-          branch: '{stream}'
-
     jobs:
-      - 'acumos-{project-name}-{stream}-push-upstream'
+      - 'acumos-{project-name}-push-upstream'
diff --git a/jjb/acumos/system-integration/system-integration-rebase-jobs.yml b/jjb/acumos/system-integration/system-integration-rebase-jobs.yml
index d63fcb2..28a0845 100644
--- a/jjb/acumos/system-integration/system-integration-rebase-jobs.yml
+++ b/jjb/acumos/system-integration/system-integration-rebase-jobs.yml
@@ -21,8 +21,6 @@
     name: system-integration-rebase
     project: system-integration
     project-name: system-integration
-    stream:
-      - master:
-          branch: '{stream}'
+
     jobs:
-      - 'acumos-{project-name}-{stream}-rebase'
+      - 'acumos-{project-name}-rebase'