如何在Linux环境下通过GitHub Actions检出TFVC仓库?
在GitHub Actions Linux环境中检出Azure DevOps TFVC仓库的方法
由于GitHub官方的actions/checkout不支持TFVC,你可以通过以下两种可行方案在Linux作业中完成检出:
方案1:使用Azure DevOps官方跨平台TF命令行工具(tf-cli)
这是官方推荐的方式,直接与TFVC交互,无需依赖Git。
步骤说明:
- 安装tf-cli:从Azure DevOps官方下载Linux版本的tf工具,添加到系统PATH。
- 认证:利用Azure DevOps个人访问令牌(PAT)完成非交互式认证,PAT需要具备TFVC仓库的读取权限。
- 创建临时工作区并检出代码:在作业目录创建临时TFVC工作区,拉取指定路径下的代码。
GitHub Actions示例配置:
jobs: tfvc-checkout: runs-on: ubuntu-latest steps: - name: 安装TF CLI工具 run: | curl -L https://aka.ms/tf-cli-linux | tar xz -C /tmp sudo mv /tmp/tf /usr/local/bin/ # 验证安装 tf --version - name: 认证到Azure DevOps env: AZURE_DEVOPS_PAT: ${{ secrets.AZURE_DEVOPS_PAT }} run: | # 设置环境变量用于非交互认证 export TF_CLI_AUTH_PAT=$AZURE_DEVOPS_PAT tf login https://dev.azure.com/你的组织名/ --auth-type pat - name: 创建临时工作区并检出代码 run: | # 在当前目录创建临时工作区 tf workspace new -collection:https://dev.azure.com/你的组织名/你的项目名/ -workspace:temp-github-actions-ws -location:. # 拉取TFVC指定路径的代码(递归拉取所有子内容) tf get $/你的项目名/TFVC代码路径 -recursive # 可选:作业完成后删除临时工作区 # tf workspace delete -collection:https://dev.azure.com/你的组织名/你的项目名/ -workspace:temp-github-actions-ws -force
方案2:使用git-tfs工具(Git兼容方式)
如果你需要用Git的工作流处理TFVC代码,可以用git-tfs将TFVC仓库镜像为Git仓库,再通过Git检出。
步骤说明:
- 安装依赖:git-tfs基于.NET,需要先安装Mono运行时和Git。
- 安装git-tfs:下载预编译的Linux版本并设置执行权限。
- 克隆TFVC仓库到本地Git:通过PAT认证,将TFVC指定路径的内容克隆为Git仓库。
GitHub Actions示例配置:
jobs: git-tfs-checkout: runs-on: ubuntu-latest steps: - name: 安装依赖(Mono + Git) run: | sudo apt-get update sudo apt-get install -y mono-complete git - name: 安装git-tfs工具 run: | sudo curl -L https://github.com/git-tfs/git-tfs/releases/download/v0.42.0/git-tfs-linux-0.42.0.tar.gz | tar xz -C /usr/local/bin/ chmod +x /usr/local/bin/git-tfs # 验证安装 git tfs --version - name: 克隆TFVC仓库为Git仓库 env: AZURE_DEVOPS_PAT: ${{ secrets.AZURE_DEVOPS_PAT }} run: | # 克隆指定TFVC路径的内容到本地Git仓库 git tfs clone https://dev.azure.com/你的组织名/你的项目名 $/你的项目名/TFVC代码路径 --username dummy --password $AZURE_DEVOPS_PAT
注意事项:
- 两种方案都需要在GitHub仓库的Secrets中添加
AZURE_DEVOPS_PAT,并确保PAT拥有**Code (Read)**权限。 - tf-cli方案更轻量、稳定,适合直接操作TFVC;git-tfs适合需要Git分支、提交等工作流的场景,但依赖Mono,性能略低。
内容的提问来源于stack exchange,提问作者noonenine
相关产品推荐
相关产品推荐

