~andrewjbeach/juju-ci-tools/make-local-patcher

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
#!/bin/bash
set -eux


usage() {
    echo "usage: $0 [--jenkins-url URL] ADDRESS"
    echo "  ADDRESS: The IP or DNS address the windows test machine."
    echo "  --jenkins-url: The location of juju-ci's Jenkins."
    echo "  --work-space: The location to build and collect in."
    echo "  --juju-home: The location of cloud-city and staging-juju-rsa."
    echo "  --juju-release-tools: The location of juju-release-tools."
    exit 1
}


while [[ "${1-}" != "" && $1 =~ ^-.*  ]]; do
    case $1 in
        --jenkins-url)
            shift
            JENKINS_URL="$1"
            ;;
        --work-space)
            shift
            WORKSPACE=$(cd $1; pwd)
            ;;
        --juju-home)
            shift
            JUJU_HOME=$(cd $1; pwd)
            ;;
        --juju-release-tools)
            shift
            RELEASE_TOOLS=$(cd $1; pwd)
            ;;
        --help)
            usage
            ;;
    esac
    shift
done

test $# -eq 1 || usage

# Remove previous tarballs and installers from the workspace
rm -r $WORKSPACE/* || echo "Nothing to clean"
mkdir -p $WORKSPACE/artifacts
touch $WORKSPACE/artifacts/empty

HOST="$1"
TARFILE=$(python <<EOT
import json
import sys
import urllib2

build_data = urllib2.urlopen(
    '$JENKINS_URL/job/build-revision/lastSuccessfulBuild/api/json')
build_json = json.load(build_data)
for artifact in build_json['artifacts']:
    filename = artifact['fileName']
    if filename.endswith('.tar.gz'):
        break
else:
    sys.exit(1)
print filename
EOT
)
ARTIFACT=$JENKINS_URL/job/build-revision/lastSuccessfulBuild/artifact
wget -q $ARTIFACT/$TARFILE
VERSION=$(basename $TARFILE .tar.gz | cut -d '_' -f2)

set +e
CI_DIR="/cygdrive/c/Users/Administrator/ci"
scp -i $JUJU_HOME/staging-juju-rsa \
    -o "StrictHostKeyChecking no" -o "UserKnownHostsFile /dev/null" \
    $WORKSPACE/$TARFILE $RELEASE_TOOLS/winbuildtest.py \
    Administrator@$HOST:$CI_DIR/
if [ $? -ne 0 ]; then
    exit 1
fi
ssh -i $JUJU_HOME/staging-juju-rsa \
    -o "StrictHostKeyChecking no" -o "UserKnownHostsFile /dev/null" \
    Administrator@$HOST \
    '/cygdrive/c/python27/python \\Users\\Administrator\\ci\\winbuildtest.py' \
    $TARFILE
if [ $? -ne 0 ]; then
    exit 1
fi
FILES="$CI_DIR/juju-setup-$VERSION.exe"
if [[ ! $VERSION =~ ^1\.20.+$ ]]; then
    FILES="$FILES $CI_DIR/juju-$VERSION-win2012-amd64.tgz"
fi
scp -i $JUJU_HOME/staging-juju-rsa \
    -o "StrictHostKeyChecking no" -o "UserKnownHostsFile /dev/null" \
    "Administrator@$HOST:$FILES" $WORKSPACE/artifacts
EXIT_STATUS=$?
set -e
exit $EXIT_STATUS