如何获取(重新创建)AzureDevOps Pipelines 中使用的不记名令牌?

How do I obtain (recreate) the bearer token used in AzureDevOps Pipelines?

我有一个失败的 yaml 基础设施即代码部署,它在第一个 yaml 步骤失败:

- task: ArchiveFiles@1
  displayName: 'Archive createADPDC.ps1 DSC files '
  inputs:
    rootFolder: 'Core/Templates/createADPDC.ps1'
    includeRootFolder: false
    replaceExistingArchive: true
    archiveFile: '$(Build.ArtifactStagingDirectory)/createADPDC.ps1.zip'

为了解决这个问题,我已经开始逐行尝试模拟托管管道服务器上正在执行的操作,但我遇到了不记名令牌。除非有更好的方法来诊断 ArtifactStagingDirectory 中丢失文件的原因,否则我会 运行 下面的命令来检查正在下载的文件和结构。

git init "C:\a\s"
Initialized empty Git repository in C:/a/1/s/.git/
git remote add origin https://MyLabs@dev.azure.com/MyLabs/Core/_git/Core
git config gc.auto 0
git config --get-all http.https://MyLabs@dev.azure.com/MyLabs/Core/_git/Core.extraheader
git config --get-all http.proxy                                                                            
git -c http.extraheader="AUTHORIZATION: bearer ***" fetch --force --tags --prune --progress --no-recurse-submodules origin
fatal: Authentication failed for 'https://dev.azure.com/MyLabs/Core/_git/Core/'

问题

或者:

  1. 确定或理解为什么 ArchiveFiles return
  2. 的更好方法是什么?

[error]ENOENT: no such file or directory, stat 'D:\a\s\Core\Templates\createADPDC.ps1'

  1. 获取不记名令牌 (PAT?) 以在位于日志中的命令行中使用的正确方法是什么
  1. 您确定目录正确吗?
  2. 您可以使用 $(system.accesstoken) 在管道脚本中访问 PAT。 确保在 yml
  3. 中的作业级别启用 persistcredentials

因此,了解管道中使用的目录结构可能是个好主意。

  • \agent_work$(Agent.BuildDirectory)
    • \agent_work\a $(Build.ArtifactStagingDirectory)
    • \agent_work\b $(Build.BinariesDirectory)
    • \agent_work\s $(Build.SourcesDirectory)

  • $(Agent.BuildDirectory) where all folders for a given build pipeline are created

    • $(Build.ArtifactStagingDirectory) artifacts are copied to before being pushed to their destination.
    • $(Build.BinariesDirectory) you can use as an output folder for compiled binaries
    • $(Build.SourcesDirectory) where your source code files are downloaded

Variables and SystemAccessToken

的链接

从错误消息来看,rootFolder 位置似乎是相对于 $(Build.SourcesDirectory) 的。为了更好地查看 $(Agent.BuildDirectory) 中的文件,我喜欢使用 tree 命令。

- task: PowerShell@2
  displayName: tree $(Agent.BuildDirectory)
  inputs:
    targetType: 'inline'
    script: 'tree /F'
    pwsh: true
    workingDirectory: '$(Agent.BuildDirectory)'