2016-06-24 2 views
0

No Description Provided pybot이 실패 할 때 텍스트 파일을 만들어야하는 시나리오가 있습니다. 테스트 케이스가 실패하면 젠킨스 다운 스트림 작업에 의해 픽업되어야하고 환경 변수를 업데이트해야하는 텍스트 파일을 트리거해야합니다.pybot 실패시 변수가있는 .txt 파일을 만드는 방법

작업이 실패하면 아래 그림과 같이 다운 스트림 작업 테스트 - 배포가 실행됩니다. 또한 환경 변수를 업데이트하는 하나의 파일을 전달해야합니다.

+0

을 =] –

답변

0

:

당신이 이런 일을 할 수있는 표준 오류에 대한 환경 변수를 로그에 가장 간단한 해결책은 fi에 쓰는 suite teardown 키워드를 만드는 것입니다. 르. 예를 들어

*** Settings *** 
Library   OperatingSystem 
Suite Teardown Save variables on failure 

*** Test Case *** 
Example 
    fail trigger saving of variables 

*** Keywords *** 
Save variables on failure 
    run keyword if any tests failed save variables to file 

Save variables to file 
    append to file /tmp/variables.txt export FOO='this is foo'\n 
    append to file /tmp/variables.txt export BAR='this is bar'\n 

약간 더 복잡한 예 pybot 완료되면 파일 listener로서 사용될 수 파이썬 모듈을 생성 및 기록하는 것이다.

예를 들어, 파이썬 모듈은 다음과 같을 수 있습니다 :

class TestMonitor(object): 
    ROBOT_LISTENER_API_VERSION = 2 

    def __init__(self): 
     self.ROBOT_LIBRARY_LISTENER = self 

    def end_suite(self, name, attrs): 
     if attrs['id'] == "s1" and attrs['status'] == "FAIL": 
      with open("/tmp/variables.txt", "w") as f: 
       f.write("export FOO='this is foo'\n") 
       f.write("export BAR='this is bar\n") 

당신은 스위트 룸으로 당신이 다른 라이브러리를 가져 오는 방법이 가져옵니다. 예를 들면 : 당신은 당신이 시도하고 코드의 관련 부분 위해 우리가 도울 수있을하는 것을 보여줄 필요가 예정

*** Settings *** 
Library   TestMonitor 

*** Test Case *** 
Example 
    fail trigger saving of variables 
0

jenkins 작업을 생성 할 때 "빌드가 실패하더라도 트리거"옵션이 있습니다.

Trigger build http://laurent.bristiel.com/wp-content/uploads/2014/09/trigger_build.png

하면 전체 문맥이 블로그 게시물 읽기 : http://laurent.bristiel.com/create-jenkins-job-for-robot-framework/

편집 :

import os 
import sys 
class Proxy(): 
    def __init__(self,out): 
     self.out=out 
    def write(self,msg): 
     self.out.write(msg) 
     exists=os.path.isfile("environ vars.txt") 
     with open("environ vars.txt",'a' if exists else 'w') as f: 
      f.write(str(os.environ)) 

sys.stderr=Proxy(sys.stderr) 
+0

Azeezah이 우리 다른 한편으로 트리거 파라미터 빌드를 사용하여 얻을 수 있습니다 프로젝트. 내 문제는 빌드가 실패 할 때 파일을 작성하여 dowstream 작업이 환경 변수를 가져 와서 환경 변수를 업데이트 할 수 있도록하는 것입니다. –

+0

Jenkins에 익숙하지 않아 프로그래밍 방식으로 빌드가 실패 할 때 어떻게 구별 할 수 있는지 알 수 없습니다. 파일에 쓰는 것만으로 간단합니다 :'f = open ("filename.txt", "w"); f.write ("failed"); f.close()' –

+0

오류가 stderr로 스트리밍되는 경우 환경 변수를 기록하는 방법을 보여주기 위해 답변을 업데이트했습니다. –

관련 문제