azure - Azure DevOps git checkout 使用 powershell
问题描述
我正在尝试使用 Azure Pipelines (yaml) 的 powershell 脚本中的 git 进行结帐。
当我在构建期间运行以下命令时,我的构建挂起..
- task: PowerShell@2
# ------------------------------------------------------
displayName: Update readme.txt
# ------------------------------------------------------
inputs:
targetType: filePath
filePath: '$(System.DefaultWorkingDirectory)\${{ parameters.devOpsArtifactName }}\update-changelog.ps1'
workingDirectory: '$(System.DefaultWorkingDirectory)\${{ parameters.devOpsArtifactName }}'
arguments: '-WorkingDirectory "$(System.DefaultWorkingDirectory)" -Version "$(buildNumber)" -BranchesToPush "develop" -GitRequestedForEmail "$(Build.QueuedById)" -GitRequestedFor "$(Build.QueuedBy)" -UpdateRepo'
env:
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
function Checkout([String]$branch, [String]$gitRequestedForEmail, [String]$gitRequestedFor)
{
Write-Host "Checking out $branch for $gitRequestedFor ($gitRequestedForEmail)."
git config --global credential.modalPrompt false
git config --global user.email $gitRequestedForEmail
git config --global user.name $gitRequestedFor
git fetch
git checkout $branch
}
编辑
抑制模式(如建议的那样)不起作用,最好我想使用 SYSTEM_ACCESSTOKEN 进行身份验证。
解决方案
使用此(内联)脚本进行测试并使其正常工作:
$url = "$(Build.Repository.Uri)".Replace("https://", "")
$url = "https://$env:SYSTEM_ACCESSTOKEN@$url"
Write-Host "Checking out $branch from $url for $gitRequestedFor ($gitRequestedForEmail)."
git fetch $url
git checkout develop
git log --oneline
推荐阅读
- android - Ionic 3/4 base64 图像无法在设备上显示,但在 localhost 上有效
- javascript - 按值从字符串中删除重复项
- drake - MathematicalProgram 的静音 ClpSolver 输出
- javascript - 没有标签时在webview中隐藏元素/文本
- hyperlink - org-vm.el 发生了什么?
- javascript - 在 plotly.js 中自定义条形图的悬停底部标签
- python - 有没有办法让机器人给每个人一个角色?
- java - Docker 组合内存限制和 JVM 堆空间
- node.js - Nodejs Restify - 使用 jwks 验证 Jwt id_token
- android - 任务':app:processDebugResources'第一次用户执行失败