Skip to content

Commit d2a7e14

Browse files
committed
Report status to github
1 parent c9e69e0 commit d2a7e14

File tree

2 files changed

+63
-10
lines changed

2 files changed

+63
-10
lines changed

.gitlab-ci.yml

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
stages:
2-
- runall
2+
- runall-and-report-to-github-pending
33
- build
44
- collate
5-
6-
# This is just a config to help trigger rest of the builds
7-
run_all_builds:
8-
image: ubuntu:latest
9-
stage: runall
10-
variables:
11-
GIT_STRATEGY: none
5+
- report-to-github-done
6+
7+
###############################################################################
8+
# report result to github
9+
###############################################################################
10+
runall-and-report-to-github-pending:
11+
image: python:2.7
12+
stage: runall-and-report-to-github-pending
1213
script:
13-
- pwd
14+
- python reportCiResult.py "gitlab-ci" "pending"
1415
when: manual
1516
allow_failure: false
1617

@@ -235,4 +236,22 @@ collate_builds:
235236
artifacts:
236237
paths:
237238
- collectedbuilds/builds.7z
238-
expire_in: 1 week
239+
expire_in: 1 week
240+
241+
242+
###############################################################################
243+
# report result to github
244+
###############################################################################
245+
report-to-github-done:failure:
246+
image: python:2.7
247+
when: on_failure
248+
stage: report-to-github-done
249+
script:
250+
- python reportCiResult.py "gitlab-ci" "failure"
251+
252+
report-to-github-done:success:
253+
image: python:2.7
254+
when: on_success
255+
stage: report-to-github-done
256+
script:
257+
- python reportCiResult.py "gitlab-ci" "success"

reportCiResult.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env python2.7
2+
3+
import os
4+
import sys
5+
import textwrap
6+
7+
def post_to_github(context, state, description=None):
8+
if 'GITHUB_TOKEN' not in os.environ:
9+
print 'NOT posting results to GitHub ($GITHUB_TOKEN not available)'
10+
return
11+
12+
payload = dict(
13+
context=context,
14+
state=state,
15+
#target_url="{CI_PROJECT_URL}/-/jobs/{CI_BUILD_ID}".format(**os.environ),
16+
target_url="{CI_PROJECT_URL}/pipelines/{CI_PIPELINE_ID}".format(**os.environ),
17+
)
18+
19+
if description:
20+
payload.update(dict(description=description))
21+
22+
import requests
23+
print 'sending status to github...'
24+
print 'sending to: {GITHUB_REPO_API}/statuses/{CI_COMMIT_SHA}'.format(**os.environ)
25+
print 'Bearer {GITHUB_TOKEN}'.format(**os.environ)
26+
response = requests.post(
27+
'{GITHUB_REPO_API}/statuses/{CI_COMMIT_SHA}'.format(**os.environ),
28+
headers={'Authorization': 'Bearer {GITHUB_TOKEN}'.format(**os.environ)},
29+
json=payload,
30+
)
31+
print response.text
32+
33+
os.system('pip install requests')
34+
post_to_github(context=sys.argv[1], state=sys.argv[2])

0 commit comments

Comments
 (0)