1

I've got the following pipeline:

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"

But I can't get access to the GitVersion output. I've tried with simply referencing $(GitVersion.FullSemVer) as well, but it gives the same result. The output from npm version is:

[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>

If I write out the actual variables it looks fine.

Edit: It seems the problem at hand is that the version number is quoted, which npm doesn't like. So the question is more how to make that not happen.

0

1 Answer 1

2

You have an extra " in $(GitVersion.FullSemVer"), just remove it and it will be fine:

echo '##vso[task.setvariable variable=buildVersion]$(GitVersion.FullSemVer)'

For example:

- task: GitVersion@4

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

- script: 'echo $(buildVersion)'

Results:

enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

Good catch with the extra quote, but it wasn't unfortunately it. I've realized what it is though. When I inject the variable it gets qouted; \npm.cmd version "0.1.0+54'"" which is the problem.
Great catch too :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.