2017년 2월 2일 목요일

Jenkins 설정 시행착오

1. MS Word 실행 실패
System.Exception: General error: 개체 참조가 개체의 인스턴스로 설정되지 않았습니다. ---> System.NullReferenceException: 개체 참조가 개체의 인스턴스로 설정되지 않았습니다.

Jenkins에서 빌드는 Windows 서비스로 실행됨
그러므로 Session0(Jenkins Builder)와 Desktop Session(MS Word)가 서로 통신 할 수 없으므로 빌드 실패
1.1 mkdir %SystemRoot%\System32\config\systemprofile\Desktop
%SystemRoot%\SysWOW64\config\systemprofile\Desktop
1.2 Jenkins Services 속성 > 로그온 > 계정 지정(T)에 윈도우 사용자 계정 설정(User Profile 항목을 설정하기 위함)
1.3 Interactive Services Detection Service 중지


2. PowerShell의 스크립트는 항상 성공적으로 종료됨
스크립트 최상단에 아래 코드를 입력하게되면 스크립트 오류 발생시 빌드 실패로 처리됨
$ErrorActionPreference = "Stop"

3. SVN log에서 텍스트 추출
[System.Console]::OutputEncoding = [System.Text.Encoding]::UTF8
#$svnlog = [xml](svn log -r HEAD --xml)
$svnlog = [xml](& svn @('log', '-r', 'HEAD', '--xml', 'http://127.0.0.1:8080/svn/hello/trunk'))
$msg = $svnlog.log.logentry.msg
[System.Console]::OutputEncoding = [System.Text.Encoding]::Default
$reg = [regex]"(#변경사항)"
$match = $reg.Match($msg)
if ($match.Success)
{
    $msg.Substring($match.Groups[1].Index+$match.Groups[1].Length+1)
}

4. Python3.5 에서 빌드 유발 스크립트
4.1 설치
pip3 install python-jenkins
4.2 스크립트
# -*- coding: utf-8 -*-                                                                                                      
import jenkins

# 사람 > 설정 > API Toekn > Show API Token                                                                                
psToken = "e209fd54627f8dcfdf8ffe717ae3016d"
server = jenkins.Jenkins("http://127.0.0.1:8080/jenkins/", username="hkim", password=psToken)
print(server.jobs_count())
server.build_job("한글-test", {"token":"remote", "TAG_NAME":"trunk", "PARA1":"한글파라123"})

댓글 없음:

댓글 쓰기