-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy path.gitlab-ci-github-status-updates.yml
More file actions
88 lines (80 loc) · 2.61 KB
/
.gitlab-ci-github-status-updates.yml
File metadata and controls
88 lines (80 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
variables:
GITHUB_AUTH: "Authorization: bearer $GITHUB_BOT_TOKEN_REPO_STATUS"
GITHUB_STATUS_API_URL: "https://api.github.com/repos/mendersoftware/$CI_PROJECT_NAME/statuses/$CI_COMMIT_SHA"
GITHUB_STATUS_API_JSON_F: '{"state": "%s", "context": "ci/gitlab", "target_url": "%s", "description": "%s"}'
stages:
# These have no effect and are only for documentation purposes. .pre and .post
# stages run at the very start and very end of a pipeline, regardless of where
# they are defined.
- .pre
- .post
.github_status_template:
tags:
- k8s-small
# Keep overhead low by using a small image with curl preinstalled.
image: ${CI_DEPENDENCY_PROXY_DIRECT_GROUP_IMAGE_PREFIX}/curlimages/curl-base
retry:
max: 2
when:
- runner_system_failure
- stuck_or_timeout_failure
before_script:
- |
send_status() {
local status="$1"
local message="$2"
local json="$(printf "$GITHUB_STATUS_API_JSON_F" "$status" "$CI_PIPELINE_URL" "$message")"
local ret=0
local output="$(curl -f -H "$GITHUB_AUTH" -d "$json" "$GITHUB_STATUS_API_URL")" || ret=$?
if [ $ret -ne 0 ]; then
if echo "$output" | grep -q "This SHA and context has reached the maximum number of statuses"; then
# This can happen for pipelines that keep running on the same master commit over and
# over, such as mender-api-docs.
return 0
fi
echo "$output" 1>&2
fi
return $ret
}
github:start:
extends: .github_status_template
dependencies: []
stage: .pre
script:
- send_status pending "Pipeline running on Gitlab"
retry:
max: 2
when:
- runner_system_failure
- stuck_or_timeout_failure
- script_failure
github:success:
extends: .github_status_template
# Remove dependencies so that we don't download all previous jobs artifacts
# Note that we cannot use "needs" as this job has to be run in the correct stage
dependencies: []
stage: .post
when: on_success
script:
- send_status success "Pipeline passed on Gitlab"
retry:
max: 2
when:
- runner_system_failure
- stuck_or_timeout_failure
- script_failure
github:failure:
extends: .github_status_template
# Remove dependencies so that we don't download all previous jobs artifacts
# Note that we cannot use "needs" as this job has to be run in the correct stage
dependencies: []
stage: .post
when: on_failure
script:
- send_status failure "Pipeline failed on Gitlab"
retry:
max: 2
when:
- runner_system_failure
- stuck_or_timeout_failure
- script_failure