如何在Windows自托管BitBucket Runner中运行其他仓库脚本
BitBucket自托管Runner问题解决方案
1. 获取跨仓库的构建脚本
自托管Runner默认仅能访问触发Pipeline的当前仓库,需手动克隆存储构建脚本的tools仓库:
- 在
bitbucket-pipelines.yml中添加克隆步骤,将工具仓库拉取到与当前仓库同级目录:
pipelines: pull-requests: '**': - step: runs-on: self.hosted script: # 替换为你的工具仓库地址,私有仓库需配置SSH密钥/应用密码授权 - git clone git@bitbucket.org:<工作区ID>/tools.git ../tools - ../tools/build.sh
- 权限配置:确保Runner主机已安装Git,且拥有工具仓库的访问权限(私有仓库可通过将SSH密钥添加到Runner主机,或使用HTTPS+应用密码实现授权)。
2. Runner容器中找不到源码的原因及解决
自托管Runner的源码不会存放在Runner核心容器中,而是在步骤临时容器/主机临时目录内:
- Docker类型Runner(如Ubuntu):每个Pipeline步骤会创建独立的临时容器,源码挂载自Runner主机的临时文件夹。查看源码可通过:
- 在Pipeline脚本中添加
pwd && ls -la,输出当前工作路径 - 用
docker ps找到当前步骤的容器ID,执行docker exec -it <容器ID> bash进入步骤容器查看
- 在Pipeline脚本中添加
- 非Docker类型Runner(如Windows):源码会被拉取到主机的临时目录,查看Runner启动日志,找到类似
Working directory: C:\Users\<用户名>\AppData\Local\Temp\bitbucket-pipelines-xxxx的路径,直接访问该目录即可看到源码。
3. 本地调试Runner(无需在线修改yml触发)
方法1:手动模拟Pipeline环境
在Runner主机上直接克隆代码并执行脚本:
# Ubuntu git clone git@bitbucket.org:<工作区ID>/your-repo.git git clone git@bitbucket.org:<工作区ID>/tools.git ../tools cd your-repo ../tools/build.sh # Windows git clone git@bitbucket.org:<工作区ID>/your-repo.git git clone git@bitbucket.org:<工作区ID>/tools.git ../tools cd your-repo ../tools/build.sh
方法2:添加调试步骤进入容器
在bitbucket-pipelines.yml中添加挂起步骤,触发后进入步骤容器调试:
pipelines: pull-requests: '**': - step: runs-on: self.hosted script: # 挂起步骤,保持容器运行 - tail -f /dev/null
触发Pipeline后,执行以下操作进入容器:
# 查看运行中的容器 docker ps # 进入容器 docker exec -it <步骤容器ID> bash
方法3:Windows Runner本地调试
Windows Runner直接在主机上执行步骤,调试方式:
- 查看Runner日志找到临时工作目录
- 直接进入该目录,手动执行构建脚本,模拟Pipeline流程
内容的提问来源于stack exchange,提问作者PJ127
相关产品推荐
相关产品推荐

