【问题标题】:Use timestamp variable in azure devops pipeline在 azure devops 管道中使用时间戳变量
【发布时间】:2020-12-06 12:31:23
【问题描述】:

我被困在 azure devops 管道中使用构建变量。

我尝试实现的目标:使用当前时间戳创建变量并使用此变量设置构建名称和工件版本(用于可追溯性)。

在我当前的配置中,powershell 脚本已成功执行,但在 npm 步骤中变量 foo 为空(请参阅下面的 yml 代码)。

variables:
  system.debug: true

name: $(TeamProject)_$(Build.DefinitionName)_$(SourceBranchName)_$(Date:yyyyMMdd)-$(Hours)$(Minutes)$(Seconds)

[...]

steps:
- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: 'Write-Host "Setting up the date time for build variable"
      $date=$(Get-Date -format yyyyMMdd-Hmmss)
      Write-Host "##vso[task.setvariable variable=foo]$date"'

- task: Npm@1
  inputs:
    command: 'custom'
    customCommand: '--no-git-tag-version version prerelease --preid=dev-$(foo)'
  displayName: 'npm version prerelease'

我的问题:为什么在 npm 步骤中变量 foo(由 powershell 引入)为空?有没有办法使用自我引入的变量 foo 设置构建名称(为构建名称和工件版本使用相同的时间戳)?

【问题讨论】:

标签: powershell azure-pipelines azure-devops-server


【解决方案1】:

您使用的 YAML 管道格式错误。你可以在下面使用 sn-p:

steps:
- powershell: |
   Write-Host "Setting up the date time for build variable"
   $date=$(Get-Date -format yyyyMMdd-Hmmss)
   Write-Host "##vso[task.setvariable variable=foo]$date"
  displayName: 'PowerShell Script'

那么这个 foo 变量应该用 powershell 成功引入。你会看到它在 follow npm 任务中展开。

【讨论】:

  • 感谢您的帮助,现在可以使用了!我最初使用菜单中的 Azure 预定义的 powershell 任务。很高兴知道这些任务会生成错误的格式...
猜你喜欢
  • 2021-11-23
  • 1970-01-01
  • 2023-02-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-12-17
  • 2019-04-29
  • 2023-02-04
相关资源
最近更新 更多