在 azure 管道中访问 GitVersion 变量以进行 javascript 构建

问题描述 投票:0回答:1

我有以下管道:

steps:

- task: GitVersion@4

- script: |
    echo '##vso[task.setvariable variable=buildVersion]$(GitVersion.FullSemVer")'

- task: NodeTool@0
  inputs:
    versionSpec: '10.x'
  displayName: 'Install Node.js'

- task: Npm@1
  inputs:
    command: 'install'
    workingDir: '$(Build.SourcesDirectory)'
  displayName: "NPM Install"

- task: Npm@1
  inputs:
    command: 'custom'
    workingDir: '$(Build.SourcesDirectory)'
    customCommand: 'run-script build'
  displayName: "NPM Build"

- task: Npm@1
  inputs:
    command: 'custom'
    workingDir: '$(Build.SourcesDirectory)'
    customCommand: 'npm version $(buildVersion)'
  displayName: "Add version"

但我无法访问 GitVersion 输出。我也尝试过简单地引用 $(GitVersion.FullSemVer) ,但它给出了相同的结果。 npm 版本的输出是:

[command]C:\windows\system32\cmd.exe /D /S /C "C:\hostedtoolcache\windows\node\10.16.0\x64\npm.cmd npm version "$(GitVersion.FullSemVer)'""
Usage: npm <command>

如果我写出实际变量,它看起来不错。

编辑: 看来手头的问题是版本号被引用,这是 npm 不喜欢的。所以问题更多的是如何让这种“不”发生。

azure-devops azure-pipelines azure-pipelines-build-task
1个回答
2
投票
"

里多了一个

$(GitVersion.FullSemVer")
,把它去掉就可以了:
echo '##vso[task.setvariable variable=buildVersion]$(GitVersion.FullSemVer)'

例如:

- task: GitVersion@4 - script: 'echo ##vso[setvariable variable=buildVersion]$(GitVersion.FullSemVer)' - script: 'echo $(buildVersion)'

结果:

© www.soinside.com 2019 - 2024. All rights reserved.