-
Notifications
You must be signed in to change notification settings - Fork 0
/
gitlab_functions.sh
executable file
·62 lines (57 loc) · 1.63 KB
/
gitlab_functions.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
#!/usr/bin/env bash
dk_login() {
if [ -n "${HUB_USER}" ]; then
echo "${HUB_TOKEN}" | docker login -u "${HUB_USER}" --password-stdin
else
echo >&2 "Error: missing 'HUB_...' protected variables."
false
fi
}
dk_logout() {
docker logout
}
dk_build() {
local context="$1"
local dockerfile="$2"
local one_image="$3"
shift 3
# rest: VAR1=value1 VAR2=value2
context="${context%/}"
local args=(-f "$context/$dockerfile" --pull -t "$one_image")
for arg; do
args[${#args[@]}]="--build-arg=$arg"
done
( set -ex;
docker build "${args[@]}" "$context" )
}
dk_push() {
local hub_repo="$1"
local one_image="$2"
shift 2
# rest: tag1 tag2
for tag; do
( set -ex;
docker tag "$one_image" "$hub_repo:$tag";
docker push "$hub_repo:$tag" )
done
}
dk_curl() {
local slug="$1"
local gitlab_token="$2"
local gitlab_domain="$3"
local gitlab_project="$4"
local cron_mode="$5"
local item="$6"
date -u -R
if [ -n "$gitlab_token" ]; then
echo >&2 "For child repo $slug:"
if [ -z "$item" ]; then
curl -X POST -F token="$gitlab_token" -F ref=master -F "variables[CRON_MODE]=$cron_mode" "https://$gitlab_domain/api/v4/projects/$gitlab_project/trigger/pipeline"
else
curl -X POST -F token="$gitlab_token" -F ref=master -F "variables[CRON_MODE]=$cron_mode" -F "variables[ITEM]=$item" "https://$gitlab_domain/api/v4/projects/$gitlab_project/trigger/pipeline"
fi
else
echo >&2 "Error: cannot read api_token_env_var for '$slug'"
false
fi
}