onnxruntime/tools/ci_build/github/azure-pipelines/templates/set-version-number-variables-step.yml
Edward Chen 6d46007028
Add explicit 'set +x' before printing a vso[] command to avoid output getting parsed again with a trailing quote. (#15986)
Here's the motivating issue:
https://github.com/microsoft/azure-pipelines-tasks/issues/10331

Noticed some problems in other repos so also updating usages in ORT.

We may be fine now without it, but this change adds some safeguard against future additions of 'set -x' for debugging.
2023-05-17 19:30:28 -07:00

44 lines
1.8 KiB
YAML

# Sets version number from VERSION.txt into a variable. As well as the git commit hash.
parameters:
versionFileDirectory: "$(Build.SourcesDirectory)"
workingDirectory: "$(Build.SourcesDirectory)"
steps:
- task: CmdLine@2
displayName: 'Set Version Number variables for Windows'
inputs:
script: |
SETLOCAL EnableDelayedExpansion
set /p _OnnxRuntimeVersion=<${{parameters.versionFileDirectory}}\VERSION_NUMBER
@echo ##vso[task.setvariable variable=OnnxRuntimeVersion;]%_OnnxRuntimeVersion%
FOR /F "tokens=* USEBACKQ" %%F IN (`git rev-parse HEAD`) DO (
@echo ##vso[task.setvariable variable=OnnxRuntimeGitCommitHash;]%%F
)
FOR /F "tokens=* USEBACKQ" %%F IN (`git rev-parse --short HEAD`) DO (
@echo ##vso[task.setvariable variable=OnnxRuntimeGitCommitHashShort;]%%F
)
workingDirectory: ${{parameters.workingDirectory}}
condition: eq(variables['Agent.OS'], 'Windows_NT')
- task: CmdLine@2
displayName: 'Set version number variables for Unix'
inputs:
script: |
# Do not output ##vso[] commands with `set -x` or they may be parsed again and include a trailing quote.
set +x
_OnnxRuntimeVersion=$(head -1 ${{parameters.versionFileDirectory}}/VERSION_NUMBER)
echo "##vso[task.setvariable variable=OnnxRuntimeVersion;]$_OnnxRuntimeVersion"
_OnnxRuntimeGitCommitHash=$(git rev-parse HEAD)
echo "##vso[task.setvariable variable=OnnxRuntimeGitCommitHash;]$_OnnxRuntimeGitCommitHash"
_OnnxRuntimeGitCommitHash=$(git rev-parse --short=8 HEAD)
echo "##vso[task.setvariable variable=OnnxRuntimeGitCommitHashShort;]$_OnnxRuntimeGitCommitHash"
workingDirectory: ${{parameters.workingDirectory}}
condition: not(eq(variables['Agent.OS'], 'Windows_NT'))