-
Notifications
You must be signed in to change notification settings - Fork 7
/
gitlab.inc.sh
186 lines (176 loc) · 4.1 KB
/
gitlab.inc.sh
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#!/usr/bin/env bash
# shellcheck disable=SC2034
set -euo pipefail
function yp_ci_env_gitlab() {
[[ "${GITLAB_CI:-}" = "true" ]] || return 0
# TODO handle external_pull_request_event
[[ "${CI_PIPELINE_SOURCE:-}" != "external_pull_request_event" ]]
export CI=true
YP_CI_NAME="GitLab CI/CD"
YP_CI_PLATFORM=gitlab
YP_CI_SERVER_HOST=${CI_SERVER_HOST:-gitlab.com}
YP_CI_REPO_SLUG=${CI_PROJECT_PATH:-}
YP_CI_ROOT=${CI_PROJECT_DIR:-}
YP_CI_IS_CRON=
[[ "${CI_PIPELINE_SOURCE:-}" != "schedule" ]] || YP_CI_IS_CRON=true
YP_CI_IS_PR=
[[ -z "${CI_MERGE_REQUEST_ID:-}" ]] || YP_CI_IS_PR=true
# 1 pipeline -> n jobs
YP_CI_JOB_ID=${CI_JOB_ID:-}
YP_CI_PIPELINE_ID=${CI_PIPELINE_ID:-}
YP_CI_JOB_URL=${CI_JOB_URL:-}
YP_CI_PIPELINE_URL=${CI_PIPELINE_URL:-${CI_PROJECT_URL:-}/-/pipelines/${YP_CI_PIPELINE_ID}}
YP_CI_PR_NUMBER=
YP_CI_PR_URL=
YP_CI_PR_REPO_SLUG=
YP_CI_PR_GIT_HASH=
YP_CI_PR_GIT_BRANCH=
[[ "${YP_CI_IS_PR}" != "true" ]] || {
YP_CI_PR_NUMBER=${CI_MERGE_REQUEST_ID:-}
YP_CI_PR_URL=${CI_PROJECT_URL:-}/-/merge_requests/${YP_CI_PR_NUMBER}
YP_CI_PR_REPO_SLUG=${CI_MERGE_REQUEST_SOURCE_PROJECT_PATH:-}
YP_CI_PR_GIT_HASH=${CI_MERGE_REQUEST_SOURCE_BRANCH_SHA:-}
YP_CI_PR_GIT_BRANCH=${CI_MERGE_REQUEST_SOURCE_BRANCH_NAME:-}
}
YP_CI_GIT_HASH=${CI_COMMIT_SHA:-}
YP_CI_GIT_BRANCH=${CI_COMMIT_REF_NAME:-}
[[ "${YP_CI_IS_PR}" != "true" ]] || YP_CI_GIT_BRANCH=${CI_MERGE_REQUEST_TARGET_BRANCH_NAME:-}
YP_CI_GIT_TAG=${CI_COMMIT_TAG:-}
YP_CI_DEBUG_MODE=${YP_CI_DEBUG_MODE:-}
}
function yp_ci_printvars_gitlab() {
printenv_all | sort -u | grep \
-e "^CHAT[=_]" \
-e "^CI[=_]" \
-e "^GITLAB[=_]" \
-e "^TRIGGER_PAYLOAD="
}
function yp_ci_known_env_gitlab() {
# see https://docs.gitlab.com/ee/ci/variables/predefined_variables.html
cat <<EOF
CHAT_CHANNEL
CHAT_INPUT
CI
CI_API_V4_URL
CI_BUILDS_DIR
CI_COMMIT_AUTHOR
CI_COMMIT_BEFORE_SHA
CI_COMMIT_BRANCH
CI_COMMIT_DESCRIPTION
CI_COMMIT_MESSAGE
CI_COMMIT_REF_NAME
CI_COMMIT_REF_PROTECTED
CI_COMMIT_REF_SLUG
CI_COMMIT_SHA
CI_COMMIT_SHORT_SHA
CI_COMMIT_TAG
CI_COMMIT_TIMESTAMP
CI_COMMIT_TITLE
CI_CONCURRENT_ID
CI_CONCURRENT_PROJECT_ID
CI_CONFIG_PATH
CI_DEBUG_TRACE
CI_DEFAULT_BRANCH
CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX
CI_DEPENDENCY_PROXY_DIRECT_GROUP_IMAGE_PREFIX
CI_DEPENDENCY_PROXY_PASSWORD
CI_DEPENDENCY_PROXY_SERVER
CI_DEPENDENCY_PROXY_USER
CI_DEPLOY_FREEZE
CI_DEPLOY_PASSWORD
CI_DEPLOY_USER
CI_DISPOSABLE_ENVIRONMENT
CI_ENVIRONMENT_NAME
CI_ENVIRONMENT_SLUG
CI_ENVIRONMENT_URL
CI_ENVIRONMENT_ACTION
CI_ENVIRONMENT_TIER
CI_HAS_OPEN_REQUIREMENTS
CI_JOB_ID
CI_JOB_IMAGE
CI_JOB_JWT
CI_JOB_JWT_V1
CI_JOB_JWT_V2
CI_JOB_MANUAL
CI_JOB_NAME
CI_JOB_STAGE
CI_JOB_STATUS
CI_JOB_TOKEN
CI_JOB_URL
CI_JOB_STARTED_AT
CI_KUBERNETES_ACTIVE
CI_NODE_INDEX
CI_NODE_TOTAL
CI_OPEN_MERGE_REQUESTS
CI_PAGES_DOMAIN
CI_PAGES_URL
CI_PIPELINE_ID
CI_PIPELINE_IID
CI_PIPELINE_SOURCE
CI_PIPELINE_TRIGGERED
CI_PIPELINE_URL
CI_PIPELINE_CREATED_AT
CI_PROJECT_CONFIG_PATH
CI_PROJECT_DESCRIPTION
CI_PROJECT_DIR
CI_PROJECT_ID
CI_PROJECT_NAME
CI_PROJECT_NAMESPACE
CI_PROJECT_PATH_SLUG
CI_PROJECT_PATH
CI_PROJECT_REPOSITORY_LANGUAGES
CI_PROJECT_ROOT_NAMESPACE
CI_PROJECT_TITLE
CI_PROJECT_URL
CI_PROJECT_VISIBILITY
CI_PROJECT_CLASSIFICATION_LABEL
CI_REGISTRY_IMAGE
CI_REGISTRY_PASSWORD
CI_REGISTRY_USER
CI_REGISTRY
CI_REPOSITORY_URL
CI_RUNNER_DESCRIPTION
CI_RUNNER_EXECUTABLE_ARCH
CI_RUNNER_ID
CI_RUNNER_REVISION
CI_RUNNER_SHORT_TOKEN
CI_RUNNER_TAGS
CI_RUNNER_VERSION
CI_SERVER_HOST
CI_SERVER_NAME
CI_SERVER_PORT
CI_SERVER_PROTOCOL
CI_SERVER_REVISION
CI_SERVER_URL
CI_SERVER_VERSION_MAJOR
CI_SERVER_VERSION_MINOR
CI_SERVER_VERSION_PATCH
CI_SERVER_VERSION
CI_SERVER
CI_SHARED_ENVIRONMENT
GITLAB_CI
GITLAB_FEATURES
GITLAB_USER_EMAIL
GITLAB_USER_ID
GITLAB_USER_LOGIN
GITLAB_USER_NAME
TRIGGER_PAYLOAD
EOF
# undocumented but observed
cat <<EOF
CI_API_GRAPHQL_URL
CI_BUILD_BEFORE_SHA
CI_BUILD_ID
CI_BUILD_NAME
CI_BUILD_REF
CI_BUILD_REF_NAME
CI_BUILD_REF_SLUG
CI_BUILD_STAGE
CI_BUILD_TOKEN
CI_JOB_NAME_SLUG
CI_JOB_TIMEOUT
CI_PROJECT_NAMESPACE_ID
CI_SERVER_TLS_CA_FILE
CI_TEMPLATE_REGISTRY_HOST
EOF
}