OpenDaylight: Improve jenkins jobs for OpenDaylight projects 82/1582/1
authorrobert.tomczyk <robert.tomczyk@est.tech>
Fri, 5 Jul 2019 08:52:58 +0000 (09:52 +0100)
committerrobert.tomczyk <robert.tomczyk@est.tech>
Fri, 5 Jul 2019 08:52:58 +0000 (09:52 +0100)
- Mirror branches from OpenDaylight 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: Ia0bb2094375ec3ccf14af28ce65f09ad0613fb3f

13 files changed:
jjb/acumos/global-templates-acumos-rebase.yaml
jjb/opendaylight/controller/controller-push-upstream-jobs.yml
jjb/opendaylight/controller/controller-rebase-jobs.yml
jjb/opendaylight/global-templates-opendaylight-push-upstream.yaml
jjb/opendaylight/global-templates-opendaylight-rebase.yaml
jjb/opendaylight/integration-test/integration-test-push-upstream-jobs.yml
jjb/opendaylight/integration-test/integration-test-rebase-jobs.yml
jjb/opendaylight/mdsal/mdsal-push-upstream-jobs.yml
jjb/opendaylight/mdsal/mdsal-rebase-jobs.yml
jjb/opendaylight/netconf/netconf-push-upstream-jobs.yml
jjb/opendaylight/netconf/netconf-rebase-jobs.yml
jjb/opendaylight/push-upstream-jobs.sh
jjb/opendaylight/rebase-jobs.sh [new file with mode: 0755]

index 5ae2c88fe78416a3c347219a603e0d444fc1b1e6..29865cfa7fbf36ba7dd78f9b362a5754b611dc71 100644 (file)
 
     parameters:
       - 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'
index 57f434603afe9f607480c104a90c8df80049442f..2fea72623fd30ca36732e751665ca20f8f186a77 100644 (file)
 # ============LICENSE_END=========================================================
 #
 - project:
-    name: controller-push-upstream
+    name: opendaylight-controller-push-upstream
     project: controller
     project-name: controller
-    stream:
-      - master:
-          branch: '{stream}'
 
     jobs:
-      - 'opendaylight-{project-name}-{stream}-push-upstream'
+      - 'opendaylight-{project-name}-push-upstream'
index a8a6719442804145d84b1300b5cef446779644dd..67f66cd380d577532dd7d744f7fdc3f6f86f54b5 100644 (file)
 # ============LICENSE_END=========================================================
 #
 - project:
-    name: controller-rebase
+    name: opendaylight-controller-rebase
     project: controller
     project-name: controller
-    stream:
-      - master:
-          branch: '{stream}'
 
     jobs:
-      - 'opendaylight-{project-name}-{stream}-rebase'
+      - 'opendaylight-{project-name}-rebase'
index f3915b2bb62c09e34f5f05fbe570a245c426da5a..63743d751957df8e401248028e1983cf693f85a2 100644 (file)
@@ -1,5 +1,5 @@
 - job-template:
-    name: 'opendaylight-{project-name}-{stream}-push-upstream'
+    name: 'opendaylight-{project-name}-push-upstream'
 
     node: infra-ubuntu1804
 
       - logrotate
 
     parameters:
-      - project-parameters:
-          project: 'opendaylight/{project}'
-          branch: '{branch}'
+      - string:
+          name: PROJECT
+          default: 'opendaylight/{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: 'opendaylight/{project}'
-          branch: '{branch}'
+          branch: '**'
           files: '**'
 
     wrappers:
index f7dab86c1bef532c7f8ee6b1dfc8a5f03fa4bfe1..e6921391aa951df8511c90aa85a350d2cd64db8c 100644 (file)
@@ -1,5 +1,5 @@
 - job-template:
-    name: 'opendaylight-{project-name}-{stream}-rebase'
+    name: 'opendaylight-{project-name}-rebase'
 
     node: infra-ubuntu1804
 
@@ -11,9 +11,6 @@
       - logrotate
 
     parameters:
-      - project-parameters:
-          project: '{project}'
-          branch: '{branch}'
       - odl-gerrit-parameters
       - string:
           name: NORDIX_REMOTE
     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:
       - odl-gerrit-trigger-change-merged:
           project: '{project}'
-          branch: '{branch}'
+          branch: '**'
           files: '**'
       - timed: "@midnight"
 
@@ -41,7 +38,7 @@
 
     builders:
       - shell:
-          !include-raw-escape: ../global/rebase-jobs.sh
+          !include-raw-escape: ./rebase-jobs.sh
 
     publishers:
       - notify-slack:
index ed5af0c3c1f8b47d674d732c26fcc26582e76aaa..e1a3d478002c4dd29c1d8ae92fcb1732f3525336 100644 (file)
 # ============LICENSE_END=========================================================
 #
 - project:
-    name: integration-test-push-upstream
+    name: opendaylight-integration-test-push-upstream
     project: integration/test
     project-name: integration-test
-    stream:
-      - master:
-          branch: '{stream}'
 
     jobs:
-      - 'opendaylight-{project-name}-{stream}-push-upstream'
+      - 'opendaylight-{project-name}-push-upstream'
index 5734206c89f5b02342cea0848eca703920615962..40465ed4272d6779a23be9f48cddb5bce0f0f59d 100644 (file)
 # ============LICENSE_END=========================================================
 #
 - project:
-    name: integration-test-rebase
+    name: opendaylight-integration-test-rebase
     project: integration/test
     project-name: integration-test
-    stream:
-      - master:
-          branch: '{stream}'
 
     jobs:
-      - 'opendaylight-{project-name}-{stream}-rebase'
+      - 'opendaylight-{project-name}-rebase'
index 9fce64697d7f65545f09ee4cee49bbc0651be712..10347b1628dd5fba2b75d15513617603a3e8461a 100644 (file)
 # ============LICENSE_END=========================================================
 #
 - project:
-    name: mdsal-push-upstream
+    name: opendaylight-mdsal-push-upstream
     project: mdsal
     project-name: mdsal
-    stream:
-      - master:
-          branch: '{stream}'
 
     jobs:
-      - 'opendaylight-{project-name}-{stream}-push-upstream'
+      - 'opendaylight-{project-name}-push-upstream'
index 9053eda44d54cd781bc6a2db2adb14b0d123896a..81a9561b8a6f7d19eddf4e8dae5093fa001e54e1 100644 (file)
 # ============LICENSE_END=========================================================
 #
 - project:
-    name: mdsal-rebase
+    name: opendaylight-mdsal-rebase
     project: mdsal
     project-name: mdsal
-    stream:
-      - master:
-          branch: '{stream}'
 
     jobs:
-      - 'opendaylight-{project-name}-{stream}-rebase'
+      - 'opendaylight-{project-name}-rebase'
index b6fb0d1a160d1dcd4f4ec435a508fcf1e3dcc9a5..9ef7db3ad7d9d51bc95866a84b07d015b27ef467 100644 (file)
 # ============LICENSE_END=========================================================
 #
 - project:
-    name: netconf-push-upstream
+    name: opendaylight-netconf-push-upstream
     project: netconf
     project-name: netconf
-    stream:
-      - master:
-          branch: '{stream}'
 
     jobs:
-      - 'opendaylight-{project-name}-{stream}-push-upstream'
+      - 'opendaylight-{project-name}-push-upstream'
index 2fbbcc48205473ec31905ee9b651238f7fe33487..e23d049dd51f7e3065fd18ae97724b27a4b7c31c 100644 (file)
 # ============LICENSE_END=========================================================
 #
 - project:
-    name: netconf-rebase
+    name: opendaylight-netconf-rebase
     project: netconf
     project-name: netconf
-    stream:
-      - master:
-          branch: '{stream}'
 
     jobs:
-      - 'opendaylight-{project-name}-{stream}-rebase'
+      - 'opendaylight-{project-name}-rebase'
index 7b6fbaaaae855bdbd9c7123820ad45ecd13be644..a7122ab8e5bc2d3129d02318660b91b0ddc3581b 100755 (executable)
 # ============LICENSE_END=========================================================
 
 #
-# This script will take the changes that are pushed to Nordix Gerrit and push upstream to Opendaylight
+# 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 OpenDaylight
+# 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 Opendaylight Gerrit
+# - The Gerrit username in Nordix needs to match with the Gerrit username in
+#   OpenDaylight
+# - infra public key on build server needs to be added to your users SSH
+#   Public Keys in OpenDaylight Gerrit
 #
-set -o nounset
-set -o pipefail
+set -euxo pipefail
 
-cd $WORKSPACE
-echo "Retrieving information from commit to push towards Opendaylight"
-project=$(git config --local remote.origin.url | awk -F "29418/opendaylight/" '{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
+opendaylight_gerrit_base='git.opendaylight.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 OpenDaylight"
 
-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 opendaylight/<opendaylight-project>
+opendaylight_project=$(echo "$GERRIT_PROJECT" | cut -d/ -f2- )
 
-if [[ $retVal -eq 0 ]]
-then
-  git remote rm upstream
-  git remote add upstream "ssh://$username@git.opendaylight.org:29418/$project.git"
-else
-  git remote add upstream "ssh://$username@git.opendaylight.org:29418/$project.git"
-fi
+# 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 OpenDaylight 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')
 
-echo "Committing changes and pushing upstream"
-git commit -as -m "$message"
-git push upstream HEAD:refs/for/$BRANCH
+opendaylight_remote_url="ssh://$username@$opendaylight_gerrit_base/$opendaylight_project"
 
-retVal1=$?
-if [[ $retVal1 -eq 0 ]]
-then
-  echo "Push upstream to Opendaylight succeeded"
+# 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
-  echo "Push upstream to Opendaylight failed"
-  exit 2
+    refspec="$commit_hash:refs/for/$GERRIT_BRANCH/$GERRIT_TOPIC"
 fi
 
-git checkout $BRANCH
-git branch -D delivery_branch
+echo >&2 "Pushing to OpenDaylight"
+
+# 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 "$opendaylight_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
diff --git a/jjb/opendaylight/rebase-jobs.sh b/jjb/opendaylight/rebase-jobs.sh
new file mode 100755 (executable)
index 0000000..8cec63a
--- /dev/null
@@ -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 OpenDaylight 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 OpenDaylight. We will make sure that branch set
+# in GERRIT_BRANCH is in sync with Nordix Gerrit.
+else
+    echo "-- Fetch branch: ${GERRIT_BRANCH} from OpenDaylight 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 OpenDaylight 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 "--------------------------------------------------------------------"