File: verify-agent-os.yml

package info (click to toggle)
python-azure 20201208%2Bgit-6
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,437,920 kB
  • sloc: python: 4,287,452; javascript: 269; makefile: 198; sh: 187; xml: 106
file content (37 lines) | stat: -rw-r--r-- 1,462 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
parameters: 
  OSVmImage: $(OSVmImage)

steps:
  - task: PythonScript@0
    displayName: Verify Agent OS
    inputs:
      scriptSource: inline
      script: |
        # Script verifies the operating system for the platform on which it is being run
        # Used in build pipelines to verify the build agent os
        # Variable: The friendly name or image name of the os to verify against
        from __future__ import print_function
        import sys
        import platform

        os_parameter = "${{ parameters.OSVmImage }}".lower()
        if os_parameter.startswith('mac') or os_parameter.startswith('darwin'):
            os_parameter = 'macOS'
        elif os_parameter.startswith('ubuntu') or os_parameter.startswith('linux'):
            os_parameter = 'Linux'
        elif os_parameter.startswith('vs') or os_parameter.startswith('win'):
            os_parameter = 'Windows'
        else:
            raise Exception('Variable OSVmImage is empty or has an unexpected value [${{ parameters.OSVmImage }}]')


        print("Job requested to run on OS: %s" % (os_parameter))

        agent_os = platform.system()
        agent_os = 'macOS' if agent_os == 'Darwin' else agent_os

        if (agent_os.lower() == os_parameter.lower()):
            print('Job ran on OS: %s' % (agent_os))
            print('##vso[task.setvariable variable=OSName]%s' % (agent_os))
        else:
            raise Exception('Job ran on the wrong OS: %s' % (agent_os))