使用 powershell 进行 Azure DevOps git checkout

标签 azure azure-devops azure-pipelines azure-pipelines-build-task

我正在尝试使用 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

关于使用 powershell 进行 Azure DevOps git checkout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54403727/

相关文章:

php - 如何将 ADFS 2.x SAML token 发送到 Dynamics CRM 本地组织数据服务?

azure - 发布管道错误: Container path not found

linux - 在托管 Linux 代理上运行的 VSTS 构建期间挂载 Azure 文件存储失败

Azure DevOps 托管代理上的 Azure 功能包?

azure-devops - 如何重置 VSTS 计数器?

azure - 如何使用 Powershell 删除 Azure DevOps 旧构建管道及其租约

azure - Cosmos DB - 更改源触发器 : The Listener for 'my-function-name' was unable to start

azure - Azure Functions 可以离线开发吗?

azure - Windows Azure 上的 32 位旧版 COM DLL

azure - Nuget.config 中的环境变量替换