问题
I am looking for a good solution to send a specific file (or a range of files) to a private GitHub repo from Azure DevOps pipeline.
You might ask why I would like to copy a file from one git to another git. But we are using Swagger to document our API, and to show Swagger UI on Confluence it can read the swagger.json from a private repo on GitHub. As far as I know Confluence cannot read the json directly from Azure DevOps.
I've tried to use the extension GitHub Release in Azure DevOps, but I don't want to create a specific release on GitHub, I just want to update specific json files.
回答1:
You could have a PowerShell task in your pipeline to execute your requirement. Example below:
#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
来源:https://stackoverflow.com/questions/58510901/send-specific-files-from-azure-devops-pipeline-to-github