我有一个包含 2 个阶段的 Yaml 管道,每个阶段包含一个作业和多个步骤。 每个作业都使用 runonce 策略与模板结合使用“windows-latest”在“Azure Pipelines”上运行。
在第一阶段,我正在检查我的 git 存储库,更新一些文件并提交这些更改。 我正在 powershell 中进行提交:
Write-Host "Fetch latest from git"
git -c http.extraheader="AUTHORIZATION: bearer $(System.AccessToken)" pull origin ${{parameters.Branch}}
Write-Host "commit all changes"
git config user.email "${{parameters.GitUserEmail}}"
git config user.name "${{parameters.GitUserName}}"
git add --all
git commit -m "${{parameters.commitMessage}}"
git tag v$(NewVersion)
git tag -a manual-export -m "manual triggered export"
Write-Host "push tag to git"
git -c http.extraheader="AUTHORIZATION: bearer $(System.AccessToken)" push --tag
Write-Host "push to code"
git -c http.extraheader="AUTHORIZATION: bearer $(System.AccessToken)" push origin ${{parameters.Branch}}
在下一阶段,我尝试进行最后的更改。 因此,我对我的存储库进行了检查(步骤),这将在本地下载文件。 不幸的是,它没有下载最新版本,我的 HEAD 仍然停留在倒数第二次提交上。
还尝试使用下面的代码强制拉取,但仍然无法获取最后一次提交。 它报告了这一点,其中 d321994 是倒数第二个提交,而不是最后一个提交。
分支“main”设置为跟踪“origin/main”。 以前的 HEAD 位置是 d321994 每日解决方案提交 切换到新分支“main” 已经更新到最新了
Write-Host "Fetching latest repository changes..."
Write-Host "$(System.DefaultWorkingDirectory)/VAB.PowerPlatform.ReleaseSolutions"
git -c http.extraheader="AUTHORIZATION: bearer $(System.AccessToken)" fetch --tags
Write-Host "Checkout"
git checkout ${{parameters.Branch}}
Write-Host "Pull"
git -c http.extraheader="AUTHORIZATION: bearer $(System.AccessToken)" pull
说实话,我不明白,我在这里做错了什么?
问候, 斯文
我可以重现同样的情况。我可以确认这是预期的行为。
当管道排队时,将设置引用。管道中的所有阶段/作业都将签出相同的引用。这就是管道的工作原理。
分支“main”设置为跟踪“origin/main”。以前的 HEAD 位置是 d321994 每日解决方案提交 切换到新分支“主” 已经是最新的
要获取第 2 阶段的最新更改,可以使用以下脚本:
Write-Host "Pull"
git config --global user.email "[email protected]"
git config --global user.name "Your Name"
git -c http.extraheader="AUTHORIZATION: bearer $(System.AccessToken)" pull origin HEAD:${{parameters.Branch}} --allow-unrelated-histories
Write-Host "Fetching latest repository changes..."
Write-Host "$(System.DefaultWorkingDirectory)/VAB.PowerPlatform.ReleaseSolutions"
git -c http.extraheader="AUTHORIZATION: bearer $(System.AccessToken)" fetch --tags
YAML 示例:
- stage: stage2
jobs:
- job:
steps:
- checkout: self
persistCredentials: true
- powershell: |
Write-Host "Pull"
git config --global user.email "[email protected]"
git config --global user.name "Your Name"
git -c http.extraheader="AUTHORIZATION: bearer $(System.AccessToken)" pull origin HEAD:${{parameters.Branch}} --allow-unrelated-histories
Write-Host "Fetching latest repository changes..."
Write-Host "$(System.DefaultWorkingDirectory)/VAB.PowerPlatform.ReleaseSolutions"
git -c http.extraheader="AUTHORIZATION: bearer $(System.AccessToken)" fetch --tags
结果: