一个用于在不同 Git 平台之间同步代码的插件。支持通过 HTTPS 或 SSH 方式同步代码到其他 Git 托管平台。
例如从 CNB 同步到 GitHub。
以下实例是从 CNB 同步到 GitHub 的,其他平台类似
main:
push:
- stages:
- name: sync to github
image: tencentcom/git-sync
settings:
target_url: https://github.com/username/repo.git
auth_type: https
username: ${GIT_USERNAME}
password: ${GIT_ACCESS_TOKEN}
branch: main
以下是从 GitHub 同步到 CNB 的示例, 注意 CNB 的 Git user 是 cnb
name: Sync to CNB
on: [push]
jobs:
sync:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Sync to CNB Repository
run: |
docker run --rm \
-v ${{ github.workspace }}:${{ github.workspace }} \
-w ${{ github.workspace }} \
-e PLUGIN_TARGET_URL="https://cnb.cool/username/repo.git" \
-e PLUGIN_AUTH_TYPE="https" \
-e PLUGIN_USERNAME="cnb" \
-e PLUGIN_PASSWORD=${{ secrets.GIT_PASSWORD }} \
-e PLUGIN_BRANCH="main" \
-e PLUGIN_GIT_USER="cnb" \
-e PLUGIN_GIT_EMAIL="cnb@cnb.cool" \
-e PLUGIN_FORCE="true" \
tencentcom/git-sync
docker run --rm \
-e PLUGIN_TARGET_URL="https://github.com/username/repo.git" \
-e PLUGIN_AUTH_TYPE="https" \
-e PLUGIN_USERNAME="your-username" \
-e PLUGIN_PASSWORD="your-access-token" \
-e PLUGIN_BRANCH="main" \
-v $(pwd):$(pwd) \
-w $(pwd) \
tencentcom/git-sync
参数名 | 必填 | 默认值 | 说明 |
---|---|---|---|
target_url | 是 | - | 目标仓库的 URL,支持 HTTPS 或 SSH 格式 |
auth_type | 否 | https | 认证类型,可选值:https 或 ssh |
username | 否* | - | HTTPS 认证时的用户名(*使用 HTTPS 时必填) |
password | 否* | - | HTTPS 认证时的密码或访问令牌(*使用 HTTPS 时必填) |
ssh_key | 否* | - | SSH 私钥内容(*使用 SSH 时必填) |
branch | 否 | - | 要推送的目标分支。不指定时推送所有分支 |
force | 否 | false | 是否强制推送(使用 --force 选项) |
push_tags | 否 | false | 是否推送标签 |
git_user | 否 | Git Sync Plugin | Git 提交时使用的用户名 |
git_email | 否 | git-sync@plugin.local | Git 提交时使用的邮箱 |
git_host | 否 | - | 自定义 Git 服务器域名 |
HTTPS 认证失败
推送失败
force: true
自定义 Git 服务器
git_host
参数设置正确