Coverage for python/lsst/verify/metadata/jenkinsci.py: 75%

4 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-06-02 09:31 +0000

1# This file is part of verify. 

2# 

3# Developed for the LSST Data Management System. 

4# This product includes software developed by the LSST Project 

5# (https://www.lsst.org). 

6# See the COPYRIGHT file at the top-level directory of this distribution 

7# for details of code ownership. 

8# 

9# This program is free software: you can redistribute it and/or modify 

10# it under the terms of the GNU General Public License as published by 

11# the Free Software Foundation, either version 3 of the License, or 

12# (at your option) any later version. 

13# 

14# This program is distributed in the hope that it will be useful, 

15# but WITHOUT ANY WARRANTY; without even the implied warranty of 

16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

17# GNU General Public License for more details. 

18# 

19# You should have received a copy of the GNU General Public License 

20# along with this program. If not, see <https://www.gnu.org/licenses/>. 

21__all__ = ['get_jenkins_env'] 

22 

23import os 

24 

25 

26def get_jenkins_env(): 

27 """Gather metadata entries from LSST DM Jenkins CI environment. 

28 

29 Returns 

30 ------- 

31 prov : `dict` 

32 Dictionary of metadata items obtained from the Jenkins CI 

33 environment. Fields are: 

34 

35 - ``'ci_id'``: Job ID in Jenkins CI. 

36 - ``'ci_name'``: Job name in Jenkins CI. 

37 - ``'ci_dataset'``: Name of the dataset being processed. 

38 - ``'ci_label'``: Value of ``${label}`` environment variable in 

39 Jenkins CI. 

40 - ``'ci_url'``: URL to job page in Jenkins CI. 

41 - ``'ci_refs'``: whitespace-delimited branch references 

42 - ``'status'``: Job return status (always ``0``). 

43 

44 Examples 

45 -------- 

46 This metadata is intended to be inserted into a job's metadata: 

47 

48 >>> from lsst.verify import Job 

49 >>> job = Job() 

50 >>> job.meta.update(get_jenkins_env()) 

51 """ 

52 

53 return { 

54 'ci_id': os.getenv('BUILD_ID', 'unknown'), 

55 'ci_name': os.getenv('PRODUCT', 'unknown'), 

56 'ci_dataset': os.getenv('dataset', 'unknown'), 

57 'ci_label': os.getenv('label', 'unknown'), 

58 'ci_refs': os.getenv('refs', 'unknown'), 

59 'ci_url': os.getenv('BUILD_URL', 'https://example.com'), 

60 'status': 0, 

61 }