【发布时间】:2022-01-02 07:06:25
【问题描述】:
我目前正在运行这个 yaml 文件:
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 "alan.haro@datashieldprotect.com"
git config user.name "alan.haro"
Write-Host "Doing git checkout..." -ForegroundColor Cyan
git checkout -b $("$(System.PullRequest.SourceBranch)".replace('refs/heads/creating-git-tags', ''))
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 & test test
- task: gitversion/execute@0
displayName: Determine SemVer
为了确保它运行良好,我必须在新 PR 的 cmets 中传递以下命令:
git commit -a -m "+'semver: minor [skip azurepipelines]'" --allow-empty
这样做,我会遇到以下问题:
" 您必须在 '+' 运算符之后提供一个值表达式。"
有谁知道我还能做些什么来防止这种类型的错误消息?
【问题讨论】:
-
我不确定。尝试用单引号包裹字符串 '+semver: patch [skip azurepipelines]'
标签: azure azure-devops azure-pipelines azure-powershell azure-pipelines-build-task