如何在Azure DevOps生成期间使用PowerShell脚本将生成工件推送到Git存储库? [英] How to push build artifacts to Git repository using PowerShell script during Azure DevOps build?

查看:52
本文介绍了如何在Azure DevOps生成期间使用PowerShell脚本将生成工件推送到Git存储库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Azure DevOps的新手,正在学习并且想要将文件从构建工件目录推送到git存储库.我正在使用此嵌入式PowerShell脚本来这样做:

I am new to Azure DevOps and learning and want to push a file from builds artifact directory to git repository. I am using this inline PowerShell script to do so:

Write-Host "Hello World"
write-host " Staging directory "$(build.artifactstagingdirectory)
git config --global user.email <useremail>
git config --global user.name <username>
git status
$CurrentPath = Get-Location
write-host "current path" $CurrentPath
$PackagePath =new-item -type directory $(get-date -f MM-dd-yyyy_HH_mm_ss)
$PackageZipPath = "$(build.artifactstagingdirectory)\<artifact to be copied>"
Copy-Item $PackageZipPath -Destination $PackagePath 
git add .
git commit -m "Adding file"
git push origin master
git status
write-host "Package Uploaded to GitHub"

但是我收到此错误,无法在回购中推送文件

But I am getting this error and not able to push the file in repo:

fatal: could not read Password for 'https://<username>@dev.azure.com': terminal prompts disabled

我想念明显的东西吗?我应该如何使用PAT/密码进行身份验证?

Am I missing the obvious? How should I use PAT/Password to authenticate?

推荐答案

不建议将工件存储在Git中!

但是如果您必须这样做并且希望 push 可以工作,那么请在 git push 行中输入用户名&密码:

But if you must to do it and you want the push will work, so in the git push line put the username & password:

git push https://username:password@azure-devops.com/repo.git master

azure-devops.com/repo.git 中,输入存储库网址(代替 origin ).

In the azure-devops.com/repo.git put the repo url (it's replace the origin).

您还可以通过以下方式使用PAT(而不是用户名和密码):

You can also use PAT (instead of username & password) in this way:

git push https://Personal%20Access%20Token:{TokenHere}@azure-devops.com/repo.git master

这篇关于如何在Azure DevOps生成期间使用PowerShell脚本将生成工件推送到Git存储库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆