You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Jenkins任务自动调用Gogs仓库的立即同步功能?

实现Jenkins调用Gogs仓库同步的方案

1. Gogs同步仓库的API说明

Gogs官方提供了触发仓库镜像同步的API,对应页面上的“立即同步”功能,具体信息如下:

  • 请求方法:POST
  • API路径:/api/v1/repos/{owner}/{repo}/mirror-sync
  • 认证方式:需要在请求头中携带Gogs用户的访问令牌(Token),令牌需拥有目标仓库的管理员权限

示例curl命令(Linux/macOS环境):

curl -X POST \
  -H "Authorization: token YOUR_GOGS_ACCESS_TOKEN" \
  http://your-gogs-server-domain/api/v1/repos/your-username/your-repo-name/mirror-sync

Windows环境PowerShell命令:

Invoke-RestMethod -Method Post `
  -Headers @{Authorization="token YOUR_GOGS_ACCESS_TOKEN"} `
  -Uri "http://your-gogs-server-domain/api/v1/repos/your-username/your-repo-name/mirror-sync"

2. Jenkins任务配置步骤

方式一:执行shell/批处理调用API

  1. 创建或打开目标Jenkins任务,进入配置页面
  2. 在构建区域添加Execute shell(Linux/macOS)或Execute Windows batch command(Windows)步骤
  3. 将对应环境的命令粘贴进去,替换令牌、Gogs地址、仓库信息
  4. 保存任务,触发构建即可调用同步功能

方式二:用HTTP Request插件(更规范)

  1. 在Jenkins插件管理中安装HTTP Request插件
  2. 进入任务配置页面,在构建区域添加HTTP Request步骤
  3. 配置参数:
    • URL:填写完整API路径,如http://your-gogs-server-domain/api/v1/repos/your-username/your-repo-name/mirror-sync
    • HTTP Method:选择POST
    • Headers:添加键值对Authorization: token YOUR_GOGS_ACCESS_TOKEN
  4. 保存任务,触发构建即可触发同步

注意事项

  • 确保Gogs访问令牌已赋予目标仓库管理员权限,否则API会返回权限错误
  • 确认Jenkins服务器能正常访问Gogs API地址(无网络拦截、防火墙限制)
  • 可在Jenkins构建日志中查看API返回结果,排查同步失败问题

内容的提问来源于stack exchange,提问作者Velan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.24 23:22:11