如何使用 AzureDevOps 管道 && PowerShell 从 Azure Repos git 下载文件
How to download file from Azure Repos git using AzureDevOps pipelines && PowerShell
我是 powershell 的新手,无法成功执行我的 powershell 脚本。
我的存储库中有一些 .zip,我需要下载它:
我使用 Azure DevOps 和 powershell 脚本来实现它:
- task: PowerShell@2
displayName: Get .zip
inputs:
targetType: 'inline'
script: |
$filePath= '$(Build.ArtifactStagingDirectory)'
$token = "tokenFromUserSettings"
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f "",$token)))
$url = "https://dev.azure.com/devopstry2305/_git/2305first_try?path=/TempTest.zip&download=true&api-version=5.0"
$result = Invoke-RestMethod -Uri $url -Method Get -ContentType "application/text" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} | Out-File $filePath
但是我得到这个错误:
我必须使用私有存储库并使用个人访问令牌。我遵循了本指南 https://gmusumeci.medium.com/how-to-download-files-from-azure-devops-repos-from-a-powershell-script-51b11d2aa7d5 但可能没有考虑到所有细节。我也在 Stack 上查看了一些关于它的问题,但不理解这些例子。
我不知道'$filePath'是什么..它是存储文件的地方吗?
$url - 在我的示例中是否正确?
如果你能纠正我的错误或给我另一种方法来解决我的任务,那就太好了。谢谢。
只要 zip 包含在您拥有管道的存储库中,就应该在检出源代码时自动下载。如果您没有定义不同的结帐路径,则此 zip 应该在 $(Build.SourcesDirectory)
内。如果您需要下载不同的存储库 zip,则需要采用另一种方法。
因此,您可以使用 powershell 列出此文件夹的内容并验证其存在。
- task: PowerShell@2
inputs:
targetType: 'inline'
script: |
# Write your PowerShell commands here.
ls $(Build.SourcesDirectory)
我是 powershell 的新手,无法成功执行我的 powershell 脚本。
我的存储库中有一些 .zip,我需要下载它:
我使用 Azure DevOps 和 powershell 脚本来实现它:
- task: PowerShell@2
displayName: Get .zip
inputs:
targetType: 'inline'
script: |
$filePath= '$(Build.ArtifactStagingDirectory)'
$token = "tokenFromUserSettings"
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f "",$token)))
$url = "https://dev.azure.com/devopstry2305/_git/2305first_try?path=/TempTest.zip&download=true&api-version=5.0"
$result = Invoke-RestMethod -Uri $url -Method Get -ContentType "application/text" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} | Out-File $filePath
但是我得到这个错误:
我必须使用私有存储库并使用个人访问令牌。我遵循了本指南 https://gmusumeci.medium.com/how-to-download-files-from-azure-devops-repos-from-a-powershell-script-51b11d2aa7d5 但可能没有考虑到所有细节。我也在 Stack 上查看了一些关于它的问题,但不理解这些例子。
我不知道'$filePath'是什么..它是存储文件的地方吗? $url - 在我的示例中是否正确?
如果你能纠正我的错误或给我另一种方法来解决我的任务,那就太好了。谢谢。
只要 zip 包含在您拥有管道的存储库中,就应该在检出源代码时自动下载。如果您没有定义不同的结帐路径,则此 zip 应该在 $(Build.SourcesDirectory)
内。如果您需要下载不同的存储库 zip,则需要采用另一种方法。
因此,您可以使用 powershell 列出此文件夹的内容并验证其存在。
- task: PowerShell@2
inputs:
targetType: 'inline'
script: |
# Write your PowerShell commands here.
ls $(Build.SourcesDirectory)