-
Notifications
You must be signed in to change notification settings - Fork 0
/
jenkins-build.sh
executable file
·81 lines (55 loc) · 1.69 KB
/
jenkins-build.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
#! /bin/bash
# jenkins-build.sh
set -e
# Assumes prior export ARTIFACTORY_ACCOUNT is available.
main()
{
set +x
annotate "Get application name and version from package.json."
APP_NAME=$(cat package.json | jq -r '.name')
APP_VERSION=$(cat package.json | jq -r '.version')
set +x
annotate "Build Docker image."
docker build -t ${APP_NAME}:${APP_VERSION} .
set +x
annotate "Remove untagged images after Docker reuses repo:tag for new build."
UNTAGGED=$(docker images --filter "dangling=true" -q)
if [ ! -z "$UNTAGGED" ]; then
docker rmi ${UNTAGGED};
fi
set +x
annotate "Run mock tests including load test in Docker container."
docker run --rm ${APP_NAME}:${APP_VERSION} grunt --no-color test
set +x
annotate "Retrieve build artifacts from Docker container."
mkdir -p artifacts
docker run --rm -v ${PWD}/artifacts:/mnt ${APP_NAME}:${APP_VERSION} /bin/bash -c 'cp artifacts/* /mnt/.'
set +x
annotate "Tag Docker image for Artifactory."
docker tag ${APP_NAME}:${APP_VERSION} ${ARTIFACTORY_ACCOUNT}.artifactoryonline.com/${APP_NAME}:${APP_VERSION}
set +x
annotate "Push Docker image to Artifactory."
docker push ${ARTIFACTORY_ACCOUNT}.artifactoryonline.com/${APP_NAME}:${APP_VERSION}
set +x
annotate "Remove tag added for Artifactory."
docker rmi ${ARTIFACTORY_ACCOUNT}.artifactoryonline.com/${APP_NAME}:${APP_VERSION}
set +x
annotate "Build complete."
}
annotate()
{
desc=$1
date=$(date)
desc_len=${#desc}
date_len=${#date}
max_len=$(($desc_len > $date_len ? $desc_len : $date_len))
dashes=$(eval printf -- '-%.s' {1..$max_len}; echo)
echo
echo "$dashes"
echo "$desc"
echo "$date"
echo "$dashes"
echo
set -x
}
main "$@"