Create jjb for datafile rebase jobs
This change converts existing datafile-rebase job [1] to jjb.
The actual rebase job is put in global templates which can be
used by any other ONAP project we have in same way as datafile
uses it.
[1] https://jenkins.nordix.org/view/ONAP/job/dcaegen2-collectors-datafile-rebase-master/
Change-Id: I9784500b9ff22d2ef8d8d63bcc7b90a900401fcf
Signed-off-by: Fatih Degirmenci <fdegir@gmail.com>
diff --git a/jjb/dcaegen2/dcaegen2-collectors-datafile-rebase-jobs.yaml b/jjb/dcaegen2/dcaegen2-collectors-datafile-rebase-jobs.yaml
new file mode 100644
index 0000000..4e17f38
--- /dev/null
+++ b/jjb/dcaegen2/dcaegen2-collectors-datafile-rebase-jobs.yaml
@@ -0,0 +1,21 @@
+---
+# this job gets triggered when a change is merged to
+# dcaegen2/collectors/datafile project on ONAP Gerrit.
+- project:
+
+ name: datafile-rebase
+
+ project: dcaegen2/collectors/datafile
+
+ project-name: dcaegen2-collectors-datafile
+
+ stream:
+ - nordix-dev:
+ branch: '{stream}'
+ upstream-branch: 'master'
+ - nordix-casablanca:
+ branch: '{stream}'
+ upstream-branch: 'casablanca'
+
+ jobs:
+ - '{project-name}-{stream}-rebase'
diff --git a/jjb/global/global-templates-rebase.yaml b/jjb/global/global-templates-rebase.yaml
new file mode 100644
index 0000000..19c3af7
--- /dev/null
+++ b/jjb/global/global-templates-rebase.yaml
@@ -0,0 +1,38 @@
+- job-template:
+ name: '{project-name}-{stream}-rebase'
+
+ node: ubuntu1804
+
+ disabled: false
+
+ concurrent: false
+
+ parameters:
+ - project-parameters:
+ project: '{project}'
+ branch: '{branch}'
+ - onap-gerrit-parameters
+ - string:
+ name: NORDIX_REMOTE
+ default: 'ssh://infra@gerrit.nordix.org:29418/{project}.git'
+ description: The remote to add for Nordix.
+ - string:
+ name: UPSTREAM_BRANCH
+ default: '{upstream-branch}'
+ description: The upstream branch to rebase against.
+
+ scm:
+ - git-scm:
+ ssh-credentials-id: nordixinfra-lfn-gerrit-ssh
+ branch: "$UPSTREAM_BRANCH"
+ refspec: ''
+
+ triggers:
+ - onap-gerrit-trigger-change-merged:
+ project: '{project}'
+ branch: "$UPSTREAM_BRANCH"
+ files: '**'
+
+ builders:
+ - shell:
+ !include-raw-escape: ./rebase-jobs.sh
diff --git a/jjb/global/jjb-macros.yaml b/jjb/global/jjb-macros.yaml
index c8b0b19..9a01636 100644
--- a/jjb/global/jjb-macros.yaml
+++ b/jjb/global/jjb-macros.yaml
@@ -107,7 +107,7 @@
prune: false
choosing-strategy: 'gerrit'
-# triggers for Nordix and upstream Gerrits
+# triggers for Nordix Gerrit
- trigger:
name: nordix-gerrit-trigger-patchset-created
triggers:
@@ -157,6 +157,26 @@
- compare-type: 'ANT'
pattern: '{files}'
+# triggers for ONAP Gerrit
+- trigger:
+ name: onap-gerrit-trigger-change-merged
+ triggers:
+ - gerrit:
+ server-name: 'ONAP Gerrit'
+ trigger-on:
+ - change-merged-event
+ - comment-added-contains-event:
+ comment-contains-value: 'remerge'
+ projects:
+ - project-compare-type: 'ANT'
+ project-pattern: '{project}'
+ branches:
+ - branch-compare-type: 'ANT'
+ branch-pattern: '**/{branch}'
+ file-paths:
+ - compare-type: 'ANT'
+ pattern: '{files}'
+
# wrappers to use for jobs
- wrapper:
name: nordixinfra-jjb-creds-wrapper
diff --git a/jjb/global/rebase-jobs.sh b/jjb/global/rebase-jobs.sh
new file mode 100755
index 0000000..b451f5f
--- /dev/null
+++ b/jjb/global/rebase-jobs.sh
@@ -0,0 +1,19 @@
+#!/bin/bash
+set -o errexit
+set -o nounset
+set -o pipefail
+
+cd $WORKSPACE
+git checkout $UPSTREAM_BRANCH -q
+git pull -q
+echo "Commit is"
+echo "-------------------------------------------"
+git show -s
+echo "-------------------------------------------"
+echo "Adding new remote for sync"
+git remote add nordix $NORDIX_REMOTE
+echo "-------------------------------------------"
+git remote -v
+echo "-------------------------------------------"
+echo "Pushing changes to Nordix BRANCH"
+git push nordix $BRANCH