Skip to content

Commit 9d24209

Browse files
authored
Sync eng/common directory with azure-sdk-tools repository (#11417)
1 parent 8033835 commit 9d24209

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Template for all Python Scripts in this repository
2+
parameters:
3+
OSVmImage: $(OSVmImage)
4+
5+
steps:
6+
- task: PythonScript@0
7+
displayName: Verify Agent OS
8+
inputs:
9+
scriptSource: inline
10+
script: |
11+
# Script verifies the operating system for the platform on which it is being run
12+
# Used in build pipelines to verify the build agent os
13+
# Variable: The friendly name or image name of the os to verfy against
14+
from __future__ import print_function
15+
import sys
16+
import platform
17+
18+
os_parameter = "${{ parameters.OSVmImage }}".lower()
19+
if os_parameter.startswith('mac') or os_parameter.startswith('darwin'):
20+
os_parameter = 'macOS'
21+
elif os_parameter.startswith('ubuntu') or os_parameter.startswith('linux'):
22+
os_parameter = 'Linux'
23+
elif os_parameter.startswith('vs') or os_parameter.startswith('win'):
24+
os_parameter = 'Windows'
25+
else:
26+
raise Exception('Variable OSVmImage is empty or has an unexpected value [${{ parameters.OSVmImage }}]')
27+
28+
29+
print("Job requested to run on OS: %s" % (os_parameter))
30+
31+
agent_os = platform.system()
32+
agent_os = 'macOS' if agent_os == 'Darwin' else agent_os
33+
34+
if (agent_os.lower() == os_parameter.lower()):
35+
print('Job ran on OS: %s' % (agent_os))
36+
print('##vso[task.setvariable variable=OSName]%s' % (agent_os))
37+
else:
38+
raise Exception('Job ran on the wrong OS: %s' % (agent_os))

0 commit comments

Comments
 (0)