Sample jobs for mirroring upstream repositories
Some sample jobs showing how to mirror upstream repositories in a manner expected by git-upstream by pushing the repo contents to the `upstream/` namespace in the local repository. Change-Id: I5c07c9d69cad2241e883fceb26b0c880b81097d9
This commit is contained in:
parent
be0d8d6bc6
commit
3384eb5ec8
|
@ -0,0 +1,5 @@
|
|||
- defaults:
|
||||
name: global
|
||||
team: ops
|
||||
gerrit-url: ssh://jenkins@review.example.com:29418
|
||||
gerrit-credentials: 279e38f3-d4dd-49a3-be01-cf3261ba14d6
|
|
@ -0,0 +1,74 @@
|
|||
- publisher:
|
||||
name: send-email-notification
|
||||
publishers:
|
||||
- email:
|
||||
recipients: team-email@example.com
|
||||
|
||||
- trigger:
|
||||
name: poll-weekly
|
||||
triggers:
|
||||
- pollscm: "@weekly"
|
||||
|
||||
- trigger:
|
||||
name: gerrit-ref-update
|
||||
triggers:
|
||||
- gerrit:
|
||||
trigger-on-patchset-upload-event: false
|
||||
trigger-on-change-merge-event: false
|
||||
trigger-on-ref-update-event: true
|
||||
trigger-on-comment-added-event: false
|
||||
override-votes: false
|
||||
silent: true
|
||||
projects:
|
||||
- project-compare-type: 'PLAIN'
|
||||
project-pattern: '{project_pattern}'
|
||||
branches:
|
||||
- branch-compare-type: 'ANT'
|
||||
branch-pattern: '**'
|
||||
|
||||
- trigger:
|
||||
name: gerrit-ref-update-plain
|
||||
triggers:
|
||||
- gerrit:
|
||||
trigger-on-patchset-uploaded-event: false
|
||||
trigger-on-change-merged-event: false
|
||||
trigger-on-ref-updated-event: true
|
||||
trigger-on-comment-added-event: false
|
||||
override-votes: false
|
||||
silent: true
|
||||
projects:
|
||||
- project-compare-type: 'PLAIN'
|
||||
project-pattern: '{project_pattern}'
|
||||
branches:
|
||||
- branch-compare-type: 'PLAIN'
|
||||
branch-pattern: '{project_branch}'
|
||||
|
||||
- scm:
|
||||
name: github-mirror-scm
|
||||
scm:
|
||||
- git:
|
||||
url: https://github.com/{project_pattern}.git
|
||||
branches:
|
||||
- origin/**
|
||||
refspec: +refs/heads/*:refs/remotes/origin/*
|
||||
name: origin
|
||||
prune: true
|
||||
clean:
|
||||
after: true
|
||||
wipe-workspace: false
|
||||
skip-tag: true
|
||||
|
||||
- scm:
|
||||
name: url-mirror-scm
|
||||
scm:
|
||||
- git:
|
||||
url: '{project_pattern}'
|
||||
branches:
|
||||
- origin/**
|
||||
refspec: +refs/heads/*:refs/remotes/origin/*
|
||||
name: origin
|
||||
prune: true
|
||||
clean:
|
||||
after: true
|
||||
wipe-workspace: false
|
||||
skip-tag: true
|
|
@ -0,0 +1,57 @@
|
|||
- job-template:
|
||||
name: 'mirror-{name}'
|
||||
project-type: freestyle
|
||||
disabled: false
|
||||
description: |
|
||||
Mirror {name} project to the upstream/* namespace
|
||||
in the local gerrit instance.<br />
|
||||
logrotate:
|
||||
daysToKeep: -1
|
||||
numToKeep: 30
|
||||
artifactDaysToKeep: -1
|
||||
artifactNumToKeep: -1
|
||||
concurrent: false
|
||||
wrappers:
|
||||
- timeout:
|
||||
timeout: 20
|
||||
fail: true
|
||||
- ssh-agent-credentials:
|
||||
user: '{gerrit-credentials}'
|
||||
parameters:
|
||||
- bool:
|
||||
name: DRY_RUN
|
||||
default: true
|
||||
description: "Whether to push repository to specified mirror or not"
|
||||
- bool:
|
||||
name: FORCE_PUSH_ALL
|
||||
default: false
|
||||
description: "Force push all refs (usually not needed)"
|
||||
properties:
|
||||
- inject:
|
||||
keep-build-variables: true
|
||||
keep-system-variables: true
|
||||
properties-content: |
|
||||
LOCAL_TEAM={team}
|
||||
LOCAL_REPO={name}
|
||||
GERRIT_URL={gerrit-url}
|
||||
scm:
|
||||
- '{scm_macro}':
|
||||
project_pattern: '{project_pattern}'
|
||||
triggers:
|
||||
- poll-weekly
|
||||
builders:
|
||||
- shell: !include-raw-escape scripts/mirror-upstream.bash
|
||||
publishers:
|
||||
- send-email-notification
|
||||
|
||||
- job-group:
|
||||
name: mirror-openstack
|
||||
jobs:
|
||||
- 'mirror-{name}':
|
||||
scm_macro: 'github-mirror-scm'
|
||||
|
||||
- job-group:
|
||||
name: mirror-git-url
|
||||
jobs:
|
||||
- 'mirror-{name}':
|
||||
scm_macro: 'url-mirror-scm'
|
|
@ -0,0 +1,11 @@
|
|||
- project:
|
||||
name: gerrit
|
||||
jobs:
|
||||
- 'mirror-git-url':
|
||||
project_pattern: https://gerrit-review.googlesource.com/p/gerrit.git
|
||||
|
||||
- project:
|
||||
name: git-upstream
|
||||
jobs:
|
||||
- 'mirror-openstack':
|
||||
project_pattern: stackforge/git-upstream
|
|
@ -0,0 +1,64 @@
|
|||
#!/bin/bash -ex
|
||||
|
||||
[ -z "${REPO_PATH}" ] && REPO_PATH="." || REPO_PATH=${REPO_PATH}
|
||||
|
||||
# The logic below is needed to preserve the old behaviour of the template
|
||||
# while providing more flexibility around the git namespace selection
|
||||
if [ -z "${GIT_NAMESPACE_PREFIX}" ];
|
||||
then
|
||||
GIT_NAMESPACE_PREFIX="upstream/"
|
||||
elif [ ${GIT_NAMESPACE_PREFIX} == '""' ];
|
||||
then
|
||||
GIT_NAMESPACE_PREFIX=""
|
||||
else
|
||||
GIT_NAMESPACE_PREFIX="${GIT_NAMESPACE_PREFIX}/"
|
||||
fi
|
||||
|
||||
[ -z "${GERRIT_URL}" ] && { echo "Required var GERRIT_URL not set"; exit 2; }
|
||||
|
||||
cd ${REPO_PATH}
|
||||
|
||||
git remote prune origin
|
||||
git fetch --tags
|
||||
git remote set-head origin -d
|
||||
|
||||
if [[ -z "${UPSTREAM_REPO}" ]]
|
||||
then
|
||||
# if using git < 1.7.5 then will need to replace the url extraction with
|
||||
# 'git config --get remote.origin.url', however this will ignore some of
|
||||
# how git allows control of the url.
|
||||
UPSTREAM_REPO="$(git ls-remote --get-url origin)"
|
||||
UPSTREAM_REPO="${UPSTREAM_REPO##*:}"
|
||||
UPSTREAM_REPO="${UPSTREAM_REPO##*/}"
|
||||
fi
|
||||
|
||||
LOCAL_REPO=${LOCAL_REPO:-${UPSTREAM_REPO}}
|
||||
[ -z "${LOCAL_TEAM}" ] && { echo "Required var LOCAL_TEAM not set"; exit 2; }
|
||||
[ -z "${LOCAL_REPO}" ] && { echo "Required var LOCAL_REPO not set"; exit 2; }
|
||||
|
||||
DRY_RUN_FLAG=`[ "${DRY_RUN}" = "true" ] && echo -n "--dry-run"` || true
|
||||
PUSH_URL="${GERRIT_URL}/${LOCAL_TEAM%% }/${LOCAL_REPO%% }.git"
|
||||
|
||||
FORCE_FLAG=
|
||||
if [ "${FORCE_PUSH_ALL}" = "true" ]
|
||||
then
|
||||
FORCE_FLAG="+"
|
||||
fi
|
||||
|
||||
SPECIFIC_REFS=""
|
||||
|
||||
OPENSTACK_META=`git ls-remote origin refs/meta/openstack/*` || true
|
||||
if [ -n "${OPENSTACK_META}" ]
|
||||
then
|
||||
git fetch origin +refs/meta/openstack/*:refs/meta/openstack/*
|
||||
SPECIFIC_REFS="${SPECIFIC_REFS}${SPECIFIC_REFS:+ }${FORCE_FLAG}refs/meta/openstack/*:refs/meta/openstack/*"
|
||||
fi
|
||||
|
||||
OPENSTACK_MILESTONE_PROPOSED=`git show-ref --verify refs/heads/milestone-proposed 2>/dev/null` || true
|
||||
if [ -n "${OPENSTACK_MILESTONE_PROPOSED}" ]
|
||||
then
|
||||
SPECIFIC_REFS="${SPECIFIC_REFS}${SPECIFIC_REFS:+ }+refs/remotes/origin/milestone-proposed:refs/heads/${GIT_NAMESPACE_PREFIX}milestone-proposed"
|
||||
fi
|
||||
|
||||
git push $DRY_RUN_FLAG "$PUSH_URL" ${SPECIFIC_REFS} ${FORCE_FLAG}refs/remotes/origin/*:refs/heads/${GIT_NAMESPACE_PREFIX}*
|
||||
git push $DRY_RUN_FLAG "$PUSH_URL" ${FORCE_FLAG}refs/tags/*:refs/tags/${GIT_NAMESPACE_PREFIX}*
|
Loading…
Reference in New Issue