-
Notifications
You must be signed in to change notification settings - Fork 162
/
pipeline.sh
executable file
·90 lines (76 loc) · 3.54 KB
/
pipeline.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
#!/bin/sh
# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -e
SCRIPTPATH=$( (cd "$(dirname "$0")" && pwd ))
echo "[INFO] CICD Pipeline for Apigee X/hybrid (Cloud Build)"
BRANCH_NAME_X=devrel-cloudbuild
SUBSTITUTIONS_X="_INT_TEST_HOST=$APIGEE_X_HOSTNAME"
SUBSTITUTIONS_X="$SUBSTITUTIONS_X,_DEPLOYMENT_ORG=$APIGEE_X_ORG"
SUBSTITUTIONS_X="$SUBSTITUTIONS_X,_APIGEE_TEST_ENV=$APIGEE_X_ENV"
SUBSTITUTIONS_X="$SUBSTITUTIONS_X,_API_VERSION=google"
SUBSTITUTIONS_X="$SUBSTITUTIONS_X,_WORK_DIR=."
SUBSTITUTIONS_X="$SUBSTITUTIONS_X,BRANCH_NAME=$BRANCH_NAME_X"
gcloud builds submit --config="$SCRIPTPATH/ci-config/cloudbuild/cloudbuild.yaml" \
--substitutions="$SUBSTITUTIONS_X"
echo "[INFO] CICD Pipeline for Apigee Edge (Cloud Build)"
BRANCH_NAME_EDGE=devrel-cloudbuild
SUBSTITUTIONS_EDGE="_INT_TEST_HOST=$APIGEE_ORG-$APIGEE_ENV.apigee.net"
SUBSTITUTIONS_EDGE="$SUBSTITUTIONS_EDGE,_DEPLOYMENT_ORG=$APIGEE_ORG"
SUBSTITUTIONS_X="$SUBSTITUTIONS_X,_WORK_DIR=."
SUBSTITUTIONS_EDGE="$SUBSTITUTIONS_EDGE,BRANCH_NAME=$BRANCH_NAME_EDGE"
gcloud builds submit --config="$SCRIPTPATH/ci-config/cloudbuild/cloudbuild.yaml" \
--substitutions="$SUBSTITUTIONS_EDGE"
echo "[INFO] Build Jenkins File Runner Image"
docker build -f "$SCRIPTPATH/jenkins-build/Dockerfile" -t apigee/devrel-jenkins-base:latest "$SCRIPTPATH/jenkins-build"
docker build -f "$SCRIPTPATH/jenkins-build/jenkinsfile-runner/Dockerfile" --build-arg baseImage=apigee/devrel-jenkins-base --build-arg baseImageTag=latest -t apigee/devrel-jenkinsfile:latest "$SCRIPTPATH/jenkins-build"
# because volume mounts don't work inside docker in docker without reference to the host file system
cat << EOF > "$SCRIPTPATH/Dockerfile-jenkins-cicd"
FROM apigee/devrel-jenkinsfile:latest
COPY --chown=jenkins . /workspace
RUN cp /workspace/ci-config/jenkins/Jenkinsfile /workspace/Jenkinsfile
EOF
docker build -f "$SCRIPTPATH/Dockerfile-jenkins-cicd" -t apigee/devrel-jenkinsfile-airports:latest "$SCRIPTPATH"
rm "$SCRIPTPATH/Dockerfile-jenkins-cicd"
echo "[INFO] CICD Pipeline for Apigee Edge (Jenkins)"
docker run \
-e APIGEE_USER \
-e APIGEE_PASS \
-e APIGEE_ORG \
-e APIGEE_TEST_ENV="$APIGEE_ENV" \
-e APIGEE_PROD_ENV="$APIGEE_ENV" \
-e TEST_HOST="$APIGEE_ORG-$APIGEE_ENV.apigee.net" \
-e API_VERSION="apigee" \
-e GIT_BRANCH=nightly \
-e AUTHOR_EMAIL="[email protected]" \
-e JENKINS_ADMIN_PASS="password" \
-e WORK_DIR="." \
apigee/devrel-jenkinsfile-airports:latest
echo "[INFO] CICD Pipeline for Apigee X (Jenkins)"
TOKEN="$(gcloud config config-helper --force-auth-refresh --format json | jq -r '.credential.access_token')"
docker run \
-e APIGEE_USER="not-used" \
-e APIGEE_PASS="not-used" \
-e GCP_SA_AUTH="token" \
-e APIGEE_TOKEN="$TOKEN" \
-e APIGEE_ORG="$APIGEE_X_ORG" \
-e APIGEE_TEST_ENV="$APIGEE_X_ENV" \
-e APIGEE_PROD_ENV="$APIGEE_X_ENV" \
-e TEST_HOST="$APIGEE_X_HOSTNAME" \
-e API_VERSION="google" \
-e GIT_BRANCH=nightly \
-e AUTHOR_EMAIL="[email protected]" \
-e JENKINS_ADMIN_PASS="password" \
-e WORK_DIR="." \
apigee/devrel-jenkinsfile-airports:latest