首页 > 解决方案 > 将特定文件从 Azure DevOps 管道发送到 Github

问题描述

我正在寻找一个很好的解决方案,将特定文件(或一系列文件)从 Azure DevOps 管道发送到私有 GitHub 存储库。

你可能会问我为什么要将文件从一个 git 复制到另一个 git。但是我们使用 Swagger 来记录我们的 API,并在 Confluence 上显示 Swagger UI,它可以从 GitHub 上的私有 repo 中读取 swagger.json。据我所知,Confluence 无法直接从 Azure DevOps 读取 json。

我尝试在 Azure DevOps 中使用扩展 GitHub Release,但我不想在 GitHub 上创建特定版本,我只想更新特定的 json 文件。

标签: githubazure-devopsswagger

解决方案


您可以在管道中有一个 PowerShell 任务来执行您的要求。下面的例子:

#Clone repo to your workspace
git clone https://github.com/repo

#assuming master is your branch
git checkout master

#Refresh repo if is already in your workspace
git pull -q 2>&1 | Write-Host

#Copy file to the worspace
XCOPY "File current location" "Git workspace location"

#Add files to the local repo
git add -A

#Commits the file to local repo:
git commit -m "Files commited."

#Pushes the changes to Git repo
git -c http.extraheader='AUTHORIZATION: bearer $env:System_AccessToken' push -q -f

推荐阅读