gpt4 book ai didi

git - $(System.PullRequest.SourceBranch) 未找到

转载 作者:行者123 更新时间:2023-12-03 04:55:11 26 4
gpt4 key购买 nike

引用文档:Microsft Guide

如果我想以 System.PullRequest.SourceBranch 为目标,我可以使用命令行任务来创建 git 标签。问题是不允许我使用它,因为通过 Azure 管道给我提供了以下错误:

System.PullRequest.SourceBranch: /home/vsts/work/_temp/be5fc781-2582-4e49-a126-7e4db3302e75.ps1:7
Line |
7 | git checkout -b $("$(System.PullRequest.SourceBranch)".replace('refs/ …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| The term 'System.PullRequest.SourceBranch' is not recognized
| as a name of a cmdlet, function, script file, or executable
| program. Check the spelling of the name, or if a path was
| included, verify that the path is correct and try again.

##[error]PowerShell exited with code '1'.

即使我尝试上面的命令,它也不会让我看到任何值:

echo $(System.PullRequest.SourceBranch)

我当前正在使用此命令:

git checkout -b $("$(System.PullRequest.SourceBranch)".replace('refs/heads/', ''))

我当前的文件如下:

trigger:
- none
## notes
pool:
vmImage: ubuntu-latest

## Job to calculate semantic version
jobs:
- job: CalculateVersion
displayName: Semantic versioning

steps:
# Checkout with persist credentials
- checkout: self
persistCredentials: true

# Install GitVersion
- task: gitversion/setup@0
displayName: Install GitVersion
inputs:
versionSpec: '5.x'

# Retrieve Pull Request Description
- task: PullRequestDescription@0
name: RetrievePullRequestDescription
displayName: Retrieve Pull Request description
inputs:
action: 'view'
outputVariable: 'PullRequest.DescriptionContent'
isOutput: true
stripIdentifiers: false

# Add git commit message that will be picked up by GitVersion ("+semver: patch/minor/major")
# Depending on the Pull Request description, where the developer has marked the type of change
- task: PowerShell@2
displayName: Add git commit message for SemVer
inputs:
targetType: inline
script: |
Write-Host "Configuring git author info.." -ForegroundColor Cyan

git config user.email "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="debfb2bfb0f0b6bfacb19ebcb2bfbcb2bff0bdb1b3" rel="noreferrer noopener nofollow">[email protected]</a>"
git config user.name "alan.haro"
Write-Host "Doing git checkout..." -ForegroundColor Cyan
git checkout -b $("$(System.PullRequest.SourceBranch)".replace('refs/heads/', ''))
Write-Host "Checking Pull Request description..." -ForegroundColor Cyan
$PRdesc = "$(RetrievePullRequestDescription.PullRequest.DescriptionContent)"
if ($PRdesc -match '(\[x\] \bFix\b)') {
Write-Host "Adding git (empty) commit message to mark this branch as a 'patch' SemVer increment." -ForegroundColor Cyan
git commit -a -m "+semver: patch [skip azurepipelines]" --allow-empty
} elseif ($PRdesc -match '(\[x\] \bFeature\b)') {
Write-Host "Adding git (empty) commit message to mark this branch as a 'minor' SemVer increment." -ForegroundColor Cyan
git commit -a -m "+semver: minor [skip azurepipelines]" --allow-empty
} elseif ($PRdesc -match '(\[x\] \bBig\b)') {
Write-Host "Adding git (empty) commit message to mark this branch as a 'major' SemVer increment." -ForegroundColor Cyan
git commit -a -m "+semver: major [skip azurepipelines]" --allow-empty
} else {
Write-Host "##vso[task.LogIssue type=error;]Please select the type of change in the Pull Request description, and Re-queue the validation." -ForegroundColor Cyan
$PRdesc
exit 1
}
Write-Host "Doing git push.." -ForegroundColor Cyan
git push --set-upstream origin $("$(System.PullRequest.SourceBranch)".replace('refs/heads/', ''))
Write-Host "Done." -ForegroundColor Cyan

# Determine the semantic version
- task: gitversion/execute@0
displayName: Determine SemVer

主要想法或概念是能够使用这个工具: Major, Minor, Patch Tags

有人知道如何解决这个问题吗?

最佳答案

如果您将脚本用于 pull 请求验证,您的脚本就会起作用:

enter image description here

如果您仅针对某个分支触发构建,它将不起作用:

enter image description here

我只测试了这一行:

git checkout -b $("$(System.PullRequest.SourceBranch)".replace('refs/heads/', ''))

检查您的构建验证策略:Improve code quality with branch policies

关于git - $(System.PullRequest.SourceBranch) 未找到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70074863/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com