Skip to content

Commit

Permalink
jenkins job trigger API - 리턴 수정 #5
Browse files Browse the repository at this point in the history
  • Loading branch information
choisungwook committed Oct 22, 2021
1 parent e4d027b commit 90d2b59
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
9 changes: 5 additions & 4 deletions app/api/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ async def info(request_trigger_dto: dto.JenkinsTriggerDTO, settings: GlobalSetti
logger.info("----------------- jenkins job trigger API 호출 -----------------------")
logger.info(f"요청정보 -> {request_trigger_dto.json()}")

job.triggerJob(request_trigger_dto, settings)
build_id = job.triggerJob(request_trigger_dto, settings)

logger.info("----------------- jenkins job trigger API 호출종료 -----------------------")

logger.info("----------------- jenkins job trigger API 호출 -----------------------")
return {
"done"
}
"build_id": build_id
}
26 changes: 16 additions & 10 deletions app/service/jenkins/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
from model.schemas import jenkins as dto


def getJobs(settgins: GlobalSettings):
jenkins_host = settgins.jenkins_host
jenkins_user = settgins.jenkins_user
jenkins_password = settgins.jenkins_password
def getJobs(settings: GlobalSettings):
jenkins_host = settings.jenkins_host
jenkins_user = settings.jenkins_user
jenkins_password = settings.jenkins_password

try:
jenkins_client = Jenkins(
Expand All @@ -25,12 +25,12 @@ def getJobs(settgins: GlobalSettings):
raise jenkins.FailConnection


# def getLastBuildNumber(settgins: GlobalSettings):
# def getLastBuildNumber(settings: GlobalSettings):
# '''Jenkins job빌드 마지막 번호 조회'''
# try:
# api_response = requests.post(
# f"{settgins.jenkins_host}?token={token}",
# auth=HTTPBasicAuth(settgins.jenkins_user, settgins.jenkins_password)
# f"{settings.jenkins_host}?token={token}",
# auth=HTTPBasicAuth(settings.jenkins_user, settings.jenkins_password)
# )
# except Exception as e:
# logger.error(f"job 마지막빌드번호 조회: jenkins 연결 실패 -> {e}")
Expand All @@ -41,18 +41,18 @@ def getJobs(settgins: GlobalSettings):
# raise jenkins.FailRequest


def triggerJob(request_trigger_dto: dto.JenkinsTriggerDTO, settgins: GlobalSettings):
def triggerJob(request_trigger_dto: dto.JenkinsTriggerDTO, settings: GlobalSettings):
'''job트리거'''
try:
url = "{}{}/build?token={}".format(
settgins.jenkins_host,
settings.jenkins_host,
request_trigger_dto.jenkins_url,
request_trigger_dto.token
)
logger.info(f"url -> {url}")
api_response = requests.post(
url,
auth=HTTPBasicAuth(settgins.jenkins_user, settgins.jenkins_password)
auth=HTTPBasicAuth(settings.jenkins_user, settings.jenkins_password)
)
except Exception as e:
logger.error(f"job 트리거: jenkins 연결 실패 -> {e}")
Expand All @@ -63,3 +63,9 @@ def triggerJob(request_trigger_dto: dto.JenkinsTriggerDTO, settgins: GlobalSetti
raise jenkins.FailRequest

logger.info("job 트리거 성공")
return getBuildhistoryNumber(api_response.headers)


def getBuildhistoryNumber(location):
'''빌드 트리거된 item id파싱'''
return int(location['Location'].split("item/")[1].replace("/", ""))

0 comments on commit 90d2b59

Please sign in to comment.