OPENDEV: TEST - Update rebase job to track and sync all upstream branches 09/1409/8
authorrobert.tomczyk <robert.tomczyk@est.tech>
Fri, 14 Jun 2019 16:08:58 +0000 (17:08 +0100)
committerrobert.tomczyk <robert.tomczyk@est.tech>
Tue, 18 Jun 2019 08:30:48 +0000 (09:30 +0100)
Change-Id: I9c26c34d2375a6a0f0de392ef3d893cd42c4d8c3

jjb/opendev/global-templates-opendev-push-upstream-test.yaml [new file with mode: 0644]
jjb/opendev/global-templates-opendev-rebase-test.yaml [new file with mode: 0644]
jjb/opendev/opendev-sandbox/opendev-sandbox-push-upstream-jobs.yml
jjb/opendev/opendev-sandbox/opendev-sandbox-rebase-jobs.yml
jjb/opendev/rebase-jobs.sh [new file with mode: 0755]

diff --git a/jjb/opendev/global-templates-opendev-push-upstream-test.yaml b/jjb/opendev/global-templates-opendev-push-upstream-test.yaml
new file mode 100644 (file)
index 0000000..df2ccca
--- /dev/null
@@ -0,0 +1,42 @@
+- job-template:
+    name: 'opendev-{project-name}-push-upstream'
+
+    node: infra-build01-ubuntu1804
+
+    disabled: false
+
+    concurrent: true
+
+    properties:
+      - logrotate
+
+    parameters:
+      - string:
+          name: PROJECT
+          default: '{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: $GERRIT_BRANCH
+          refspec: $GERRIT_REFSPEC
+
+    triggers:
+      - nordix-gerrit-patchset-created-or-push-upstream:
+          project: 'opendev/{project}'
+          branch: '**'
+          files: '**'
+
+    wrappers:
+      - build-timeout:
+          timeout: 10
+
+    builders:
+      - shell:
+          !include-raw-escape: ./push-upstream-jobs.sh
+
+    publishers:
+      - notify-slack:
+          slack-channel: '#infra'
diff --git a/jjb/opendev/global-templates-opendev-rebase-test.yaml b/jjb/opendev/global-templates-opendev-rebase-test.yaml
new file mode 100644 (file)
index 0000000..0112cd8
--- /dev/null
@@ -0,0 +1,47 @@
+- job-template:
+    name: 'opendev-{project-name}-rebase'
+
+    node: infra-build01-ubuntu1804
+
+    disabled: false
+
+    concurrent: false
+
+    properties:
+      - logrotate
+
+    parameters:
+      - opendev-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/opendev/{project}.git'
+          description: The remote to add for Nordix.
+
+    scm:
+      - git-scm:
+          ssh-credentials-id: nordixinfra-lfn-gerrit-ssh
+          branch: '*'
+          refspec: ''
+
+    triggers:
+      - opendev-gerrit-trigger-change-merged:
+          project: '{project}'
+          branch: '**'
+          files: '**'
+      - timed: "@midnight"
+
+    wrappers:
+      - build-timeout:
+          timeout: 10
+
+    builders:
+      - shell:
+          !include-raw-escape: ./rebase-jobs.sh
+
+    publishers:
+      - notify-slack:
+          slack-channel: '#infra'
index 8862f067693f046af2a6d0c8f80dd71e541a32e2..88dc761f6ed17784feaab9c30cbd881b093983d6 100644 (file)
@@ -21,9 +21,6 @@
     name: opendev-sandbox-push-upstream
     project: opendev/sandbox
     project-name: opendev-sandbox
     name: opendev-sandbox-push-upstream
     project: opendev/sandbox
     project-name: opendev-sandbox
-    stream:
-      - master:
-          branch: '{stream}'
 
     jobs:
 
     jobs:
-      - 'opendev-{project-name}-{stream}-push-upstream'
+      - 'opendev-{project-name}-push-upstream'
index 71f1fd63b98d5e7282bcf3cbbb6710b19245d355..81d1eb49cf89a89a66f8444661cf6b88bab1413d 100644 (file)
@@ -21,9 +21,6 @@
     name: opendev-sandbox-rebase
     project: opendev/sandbox
     project-name: opendev-sandbox
     name: opendev-sandbox-rebase
     project: opendev/sandbox
     project-name: opendev-sandbox
-    stream:
-      - master:
-          branch: '{stream}'
 
     jobs:
 
     jobs:
-      - 'opendev-{project-name}-{stream}-rebase'
+      - 'opendev-{project-name}-rebase'
diff --git a/jjb/opendev/rebase-jobs.sh b/jjb/opendev/rebase-jobs.sh
new file mode 100755 (executable)
index 0000000..b223f90
--- /dev/null
@@ -0,0 +1,40 @@
+#!/bin/bash
+set -o errexit
+set -o nounset
+set -o pipefail
+
+cd $WORKSPACE
+# 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 OpenDev 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 OpenDev. We will make sure that branch set
+# in GERRIT_BRANCH is in sync with Nordix Gerrit.
+else
+    echo "-- Fetch branch: ${GERRIT_BRANCH} from OpenDev 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 OpenDev 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 "--------------------------------------------------------------------"
+# Make sure the Nordix is set from Jenkins Job configuration
+# parameter: NORDIX_REMOTE in next job run
+if git remote | grep nordix > /dev/null ; then
+    git remote rm nordix
+fi