赞
踩
github仓库:https://github.com/nuptaxin/jenkins-hello
目标gitee仓库(无需手动创建):https://gitee.com/nuptaxin/jenkins-hello
首先在本地生成一个ssh密钥对
renzhengxin@renzhenxindeMBP ~ % ssh-keygen -t rsa -f ~/Documents/dst_id_rsa Generating public/private rsa key pair. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /Users/renzhengxin/Documents/dst_id_rsa Your public key has been saved in /Users/renzhengxin/Documents/dst_id_rsa.pub The key fingerprint is: SHA256:21rVVMK/wQ4jTPbHqHldkhf4ZoQhoCa7DrcPlt/lX2g renzhengxin@renzhenxindeMBP The key's randomart image is: +---[RSA 3072]----+ | ... o= .| | . o.o.= | | . o + . Bo.| | + o BoO+| | . S = Xo+| | o o + ..+ | | . * . o..E . | | = + .oo . . | | o.o.. ... | +----[SHA256]-----+
在github打开Settings
->Secrets
->Actions
->New Repository secret
,新建一个secret
名为GITEE_PRIVATE_KEY,值为上面生成的密钥对的私钥(文件:/Users/renzhengxin/Documents/dst_id_rsa)
然后登录到gitee,在设置
->安全设置
->SSH公钥
中添加上面生成的密钥对的公钥(文件:/Users/renzhengxin/Documents/dst_id_rsa.pub),标题随意,此处标题使用了GITEE_PUBLIC_KEY
在gitee打开设置
->安全设置
->私人令牌
->生成新令牌
命名随意,此处命名为gitee-token
复制生成的令牌值
在github打开Settings
->Secrets
->Actions
->New repository secret
名为GITEE_TOKEN,值为上面复制的令牌值
github的secrets:
在刚才的GitHub仓库中,新建 .github/workflows/SyncToGitee.yml
文件,其中.github/workflows/
是固定的目录名
name: Sync Github Repos To Gitee on: push: branches: - master jobs: build: runs-on: ubuntu-20.04 steps: - name: Sync Github Repos To Gitee # 名字随便起 uses: Yikun/hub-mirror-action@v1.1 # 使用Yikun/hub-mirror-action with: src: github/nuptaxin # 源端账户名(github) dst: gitee/nuptaxin # 目的端账户名(gitee) dst_key: ${{ secrets.GITEE_PRIVATE_KEY }} # SSH密钥对中的私钥 dst_token: ${{ secrets.GITEE_TOKEN }} # Gitee账户的私人令牌 account_type: user # 账户类型 clone_style: "https" # 使用https方式进行clone,也可以使用ssh debug: true # 启用后会显示所有执行命令 force_update: true # 启用后,强制同步,即强制覆盖目的端仓库 static_list: "jenkins-hello" # 静态同步列表,在此填写需要同步的仓库名称,可填写多个 timeout: '600s' # git超时设置,超时后会自动重试git操作
提交该action,观察github上的执行视图
点击该action,可以查看执行状态及执行日志
gitee上查看jenkins-hello创建成功并同步
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。