如何在 Azure DevOps 构建期间使用 PowerShell 脚本将构建工件推送到 Git 存储库?

杰格拉特·莫迪

我是 Azure DevOps 的新手,正在学习并希望将文件从构建工件目录推送到 git 存储库。我正在使用此内联 PowerShell 脚本来执行此操作:

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"

但是我收到此错误并且无法在 repo 中推送文件:

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

我错过了明显的吗?我应该如何使用 PAT/密码进行身份验证?

谢基·阿布拉姆奇克

不建议在 Git 中存储工件!

但是如果你必须这样做并且你想要它push会起作用,那么git push在行中输入用户名和密码:

git push https://username:[email protected]/repo.git master

azure-devops.com/repo.git放入 repo url(它替换origin)。

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

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Azure DevOps:如何从发布管道中的PowerShell脚本从构建Azure管道中检索构建工件?

在 Openshift 构建期间使用真正的 git 存储库?

如何从 Azure DevOps 中的构建管道创建更改集以将某些文件推送到我的存储库中

如何将Azure DevOps Git存储库与Azure静态Web应用一起使用?

如何在Azure DevOps管道中管理构建工件?

如何在Azure DevOps中删除Git存储库?

Azure DevOps 构建工件存储在哪里

如何清除所有构建工件的 ASP.NET MVC 项目以发送到 git 存储库?

当脚本保存在 git 存储库中时,如何将 JMeter 与 Azure DevOps Pipeline 集成?

将启用了LFS的本地Git存储库推送到空的Azure Devops失败

Azure DevOps 使用 GitHub 中的存储库构建管道

Azure DevOps-如何使用多个存储库创建构建管道?

Azure DevOps:如何使用REST API存储库在GIT存储库中创建文件夹

如何在构建工件文件中注入 Azure DevOps 管道运行号?

将Github Git存储库迁移到Azure DevOps TFVC

如何将 Azure DevOps 构建工件复制到同一管道中的 Docker 映像构建?

如何将克隆的 git 存储库 zip 文件添加到 Azure devops?

如何使用Azure DevOps REST Api从Git存储库下载分支中的文件?

Azure DevOps管道-使用多个Git源存储库时如何标记源

如何在 azure devops 管道中使用来自 azure devops 存储库的共享文件

由于身份验证失败,无法将本地git推送到Azure DevOps git存储库,但密码正确

如何在 Azure DevOps Git 存储库的 README.MD 中创建内联链接?

如何使用Azure CLI创建Azure DevOps存储库

git存储库的Azure DevOps语言?

Azure DevOps - Git 存储库设置

使用Powershell的Azure DevOps git签出

如何使用Git将标签推送到远程存储库?

基于不同存储库分支的 Azure DevOps 管道构建名称

从 git 存储库运行 Azure VM 扩展 Powershell 脚本