github.com/shashidharatd/test-infra@v0.0.0-20171006011030-71304e1ca560/jenkins/diff-job-config-patch.sh (about)

     1  #!/usr/bin/env bash
     2  
     3  # Copyright 2016 The Kubernetes Authors.
     4  #
     5  # Licensed under the Apache License, Version 2.0 (the "License");
     6  # you may not use this file except in compliance with the License.
     7  # You may obtain a copy of the License at
     8  #
     9  #     http://www.apache.org/licenses/LICENSE-2.0
    10  #
    11  # Unless required by applicable law or agreed to in writing, software
    12  # distributed under the License is distributed on an "AS IS" BASIS,
    13  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14  # See the License for the specific language governing permissions and
    15  # limitations under the License.
    16  
    17  # Uses the kubekins-job-builder Docker image to compute the differences in
    18  # the Jenkins job config XML, comparing the current git branch against master.
    19  # The diff is printed at the end, assuming everything parsed successfully.
    20  
    21  # Note: anecdotal evidence suggests this doesn't work correctly on OS X.
    22  # If you find that there is no diff being generated, you may want to try setting
    23  # OUTPUT_DIR to some directory in your home directory.
    24  
    25  # When running this script from inside Docker, you must set REPO_ROOT to point
    26  # to the path to the repository on the host, and DOCKER_VOLUME_OUTPUT_DIR must
    27  # point to the path of $OUTPUT_DIR on the host. This is due to the way volume
    28  # mounts work in Docker-in-Docker.
    29  
    30  set -o errexit
    31  set -o nounset
    32  set -o pipefail
    33  
    34  readonly JOB_CONFIGS_ROOT="jenkins/job-configs"
    35  readonly JOB_BUILDER_IMAGE="gcr.io/google_containers/kubekins-job-builder:5"
    36  
    37  REPO_ROOT=$(cd $(dirname "${BASH_SOURCE}")/.. && pwd)
    38  REPO_DIR=${REPO_DIR:-"${REPO_ROOT}"}
    39  
    40  readonly output_dir=${OUTPUT_DIR:=$(mktemp -d -t JJB-XXXXX)}
    41  readonly docker_volume_output_dir=${DOCKER_VOLUME_OUTPUT_DIR:="${output_dir}"}
    42  
    43  mkdir -p "${output_dir}/upstream" "${output_dir}/patch"
    44  
    45  echo "Saving output in ${output_dir}"
    46  
    47  readonly common_commands="\
    48    git describe --long --tags --always --dirty --abbrev=14 >/output/gitversion.txt && \
    49    git rev-parse --abbrev-ref HEAD >/output/gitbranch.txt && \
    50    jenkins-jobs test \
    51      '${JOB_CONFIGS_ROOT}:${JOB_CONFIGS_ROOT}/kubernetes-jenkins' \
    52      -o /output/kubernetes-jenkins && \
    53    jenkins-jobs test \
    54      '${JOB_CONFIGS_ROOT}:${JOB_CONFIGS_ROOT}/kubernetes-jenkins-pull' \
    55      -o /output/kubernetes-jenkins-pull"
    56  
    57  # We don't want to modify the local source in any way, so mount it read-only
    58  # and checkout the master branch in a separate directory.
    59  docker run --rm=true -i \
    60    -v "${REPO_DIR}:/test-infra:ro" \
    61    -v "${docker_volume_output_dir}/upstream:/output" \
    62    "${JOB_BUILDER_IMAGE}" \
    63    bash -c "git clone -b master --single-branch /test-infra /workspace && \
    64      cd /workspace && ${common_commands}"
    65  
    66  docker run --rm=true -i \
    67    -v "${docker_volume_output_dir}/patch:/output" \
    68    -v "${REPO_DIR}:/test-infra:ro" \
    69    "${JOB_BUILDER_IMAGE}" \
    70    bash -c "${common_commands}"
    71  
    72  readonly result_diff=$(diff -ruN "${output_dir}/upstream" "${output_dir}/patch" || true)
    73  echo "${result_diff}"
    74  if [[ "${TRAVIS:-}" != "true" ]]; then
    75    less -fF <(echo "${result_diff}")
    76  fi