Pra*_*ani 5 yaml azure devops azure-devops azure-pipelines
我试图根据逻辑获取一些值来形成我的点网应用程序的版本号。
我正在使用 Azure DevOps 并创建了一个管道 (YAML)。在管道中,我创建了几个变量,它们通过使用一些计算逻辑来获取值。下面是代码。
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
old_date: '20210601'
latest_date: '20210603'
PSI: ($(latest_date)-$(old_date))/56+1
totalsprints: '($(latest_date)-$(old_date))/14'
sprint: '$(totalsprints)%4+1'
majorversion: '2.'
dot: '.'
name: '$(majorversion)$(Year:yy)$(PSI)$(dot)$(sprint)$(dot)$(Date:MMdd)'
Run Code Online (Sandbox Code Playgroud)
上面的逻辑在 old_date 中设置了一个默认日期,从latest_date 中减去它并除以 56 以获得一些值。结果的下一个值是我们的 PSI。冲刺的计算方式相同。这样做是为了形成我们的 Dot Net 应用程序的版本号。像这样的“2.212.2.0312”
相同类型的逻辑也适用于 Jenkins 的 Groovy 脚本。但在这里,它显示 PSI = ($(latest_date)-$(old_date))/56+1 并且不评估任何内容。
感谢您对此的回应。
这不可能。变量表达式中不支持数学表达式。您可以在这里查看。但是,您可以如上所述声明静态变量,并将所有计算移至步骤并动态设置内部版本号,如下所示
它可以是这样的:
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
old_date: '20210601'
latest_date: '20210603'
# PSI: ${{ (variables.latest_date-variables.old_date)/56+1}}
# totalsprints: ${{ (variables.latest_date-variables.old_date)/14 }}
# sprint: ${{ variables.totalsprints%4+1 }}
majorversion: '2.'
dot: '.'
#name: '$(majorversion)$(Year:yy)$(PSI)$(dot)$(sprint)$(dot)$(Date:MMdd)'
trigger: none
pr: none
pool:
vmImage: ubuntu-latest
name: 'Set dynamically below in a task'
steps:
- task: PowerShell@2
displayName: Set the name of the build (i.e. the Build.BuildNumber)
inputs:
targetType: 'inline'
script: |
[int] $PSI = (([int] $(latest_date))-([int] $(old_date)))/56+1
[int] $totalsprints = ( ([int] $(latest_date))-([int] $(old_date)))/14
[int] $sprint = $totalsprints%4+1
$year = Get-Date -Format "yy"
$monthDay = Get-Date -Format "MMdd"
[string] $buildName = "$(majorversion)$year$PSI.$sprint.$monthDay"
Write-Host "Setting the name of the build to '$buildName'."
Write-Host "##vso[build.updatebuildnumber]$buildName"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4182 次 |
| 最近记录: |