forked from crc-org/crc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
centos_ci.sh
131 lines (113 loc) · 3.79 KB
/
centos_ci.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
#!/bin/bash
# Output command before executing
set -x
# Exit on error
set -e
########################################################
# Exit with message on failure of last executed command
# Arguments:
# $1 - Exit code of last executed command
# $2 - Error message
########################################################
function exit_on_failure() {
if [[ "$1" != 0 ]]; then
echo "$2"
exit 1
fi
}
# Source environment variables of the jenkins slave
# that might interest this worker.
function load_jenkins_vars() {
if [ -e "jenkins-env" ]; then
cat jenkins-env \
| grep -E "(JENKINS_URL|GIT_BRANCH|GIT_COMMIT|BUILD_NUMBER|ghprbSourceBranch|ghprbActualCommit|BUILD_URL|ghprbPullId|CICO_API_KEY|GITHUB_TOKEN|JOB_NAME|RELEASE_VERSION|RH_REGISTRY_PASSWORD|CRC_BUNDLE_PASSWORD)=" \
| sed 's/^/export /g' \
> ~/.jenkins-env
source ~/.jenkins-env
fi
echo 'CICO: Jenkins ENVs loaded'
}
function install_required_packages() {
# Install EPEL repo
yum -y install epel-release
# Get all the deps in
yum -y install make \
git \
curl \
kvm \
qemu-kvm \
libvirt \
python-requests \
libvirt-devel \
jq \
gcc \
golang \
libcurl-devel \
glib2-devel \
openssl-devel \
asciidoc \
unzip
echo 'CICO: Required packages installed'
}
function setup_golang() {
# Show which version of golang in the offical repo.
go version
# Setup GOPATH
mkdir $HOME/gopath $HOME/gopath/src $HOME/gopath/bin $HOME/gopath/pkg
export GOPATH=$HOME/gopath
export PATH=$GOROOT/bin:$GOPATH/bin:$PATH
}
function perform_artifacts_upload() {
set +x
# For PR build, GIT_BRANCH is set to branch name other than origin/master
if [[ "$GIT_BRANCH" = "origin/master" ]]; then
# http://stackoverflow.com/a/22908437/1120530; Using --relative as --rsync-path not working
mkdir -p crc/master/$BUILD_NUMBER/
cp out/* crc/master/$BUILD_NUMBER/
RSYNC_PASSWORD=$1 rsync -a --relative crc/master/$BUILD_NUMBER/ [email protected]::minishift/crc/
echo "Find Artifacts here http://artifacts.ci.centos.org/${REPO_OWNER}/${REPO_NAME}/master/$BUILD_NUMBER ."
else
# http://stackoverflow.com/a/22908437/1120530; Using --relative as --rsync-path not working
mkdir -p pr/$ghprbPullId/
cp -R out/* pr/$ghprbPullId/
RSYNC_PASSWORD=$1 rsync -a --relative pr/$ghprbPullId/ [email protected]::minishift/crc/
echo "Find Artifacts here http://artifacts.ci.centos.org/minishift/crc/pr/$ghprbPullId ."
fi
}
function get_bundle() {
mkdir $HOME/Downloads
curl -L 'https://github.com/code-ready/crc-ci-jobs/releases/download/4.0.1/crc_bundle.zip' -o $HOME/Downloads/bundle.zip
unzip -P $CRC_BUNDLE_PASSWORD $HOME/Downloads/bundle.zip -d $HOME/Downloads/
}
function upload_logs() {
set +x
# http://stackoverflow.com/a/22908437/1120530; Using --relative as --rsync-path not working
mkdir -p pr/$ghprbPullId/
cp -R test/integration/out/test-results/* pr/$ghprbPullId/
cp $HOME/.crc/crc.log pr/$ghprbPullId/crc_$(date '+%Y_%m_%d_%H_%M_%S').log
RSYNC_PASSWORD=$1 rsync -a --relative pr/$ghprbPullId/ [email protected]::minishift/crc/
echo "Find Logs here: http://artifacts.ci.centos.org/minishift/crc/pr/$ghprbPullId ."
}
function run_tests() {
set +e
make integration
if [[ $? -ne 0 ]]; then
upload_logs $1
exit 1
fi
}
# Execution starts here
load_jenkins_vars
install_required_packages
setup_golang
export TERM=xterm-256color
get_bundle
# setup to run integration tests
make
make fmtcheck
make cross
crc setup
# Retrieve password for rsync and run integration tests
CICO_PASS=$(echo $CICO_API_KEY | cut -d'-' -f1-2)
run_tests $CICO_PASS
perform_artifacts_upload $CICO_PASS