Enable verify jobs for external scenarios
[releng.git] / jjb / xci / xci-set-scenario.sh
1 #!/bin/bash
2 # SPDX-license-identifier: Apache-2.0
3 ##############################################################################
4 # Copyright (c) 2018 SUSE and others.
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
10 set -o errexit
11 set -o nounset
12 set -o pipefail
13
14 #----------------------------------------------------------------------
15 # This script is used by CI and executed by Jenkins jobs.
16 # You are not supposed to use this script manually if you don't know
17 # what you are doing.
18 #----------------------------------------------------------------------
19
20 # skip the healthcheck if the patch doesn't impact the deployment
21 if [[ "$GERRIT_TOPIC" =~ skip-verify|skip-deployment ]]; then
22     echo "Skipping the healthcheck!"
23     exit 0
24 fi
25
26 # skip the deployment if the scenario is not supported on this distro
27 OPNFV_SCENARIO_REQUIREMENTS=$WORKSPACE/xci/opnfv-scenario-requirements.yml
28 if ! sed -n "/^- scenario: $DEPLOY_SCENARIO$/,/^$/p" $OPNFV_SCENARIO_REQUIREMENTS | grep -q $DISTRO; then
29     echo "# SKIPPED: Scenario $DEPLOY_SCENARIO is NOT supported on $DISTRO"
30     exit 0
31 fi
32
33 # if change is coming to releng-xci, continue as usual until that part is fixed as well
34 if [[ $GERRIT_PROJECT == "releng-xci" ]]; then
35     # save the scenario name into java properties file to be injected to downstream jobs via envInject
36     echo "Recording scenario name for downstream jobs"
37     rm /tmp/$GERRIT_CHANGE_NUMBER/scenario.properties
38     echo "DEPLOY_SCENARIO=os-nosdn-nofeature" > /tmp/$GERRIT_CHANGE_NUMBER/scenario.properties
39     exit 0
40 fi
41
42 # projects develop different scenarios and jobs need to know which scenario got the
43 # change under test so the jobs can deploy and test the right scenario.
44 # we need to fetch the change and look at the changeset to find out the scenario instead
45 # of hardcoding scenario per project.
46 PROJECT_CLONE_LOCATION=/tmp/${GERRIT_PROJECT}_${GERRIT_CHANGE_NUMBER}
47 rm -rf $PROJECT_CLONE_LOCATION
48 git clone https://gerrit.opnfv.org/gerrit/$GERRIT_PROJECT $PROJECT_CLONE_LOCATION
49 cd $PROJECT_CLONE_LOCATION
50 git fetch https://gerrit.opnfv.org/gerrit/$GERRIT_PROJECT $GERRIT_REFSPEC && git checkout FETCH_HEAD
51 DEPLOY_SCENARIO=$(git diff HEAD^..HEAD --name-only | grep scenarios | sed -r 's/scenarios\/(.*?)\/role.*/\1/' | uniq)
52
53 # ensure single scenario is impacted
54 if [[ $(echo $DEPLOY_SCENARIO | wc -w) != 1 ]]; then
55     echo "Change impacts multiple scenarios!"
56     echo "XCI doesn't support testing of changes that impact multiple scenarios currently."
57     echo "Please split your change into multiple different/dependent changes, each modifying single scenario."
58     exit 1
59 fi
60
61 # save the scenario name into java properties file to be injected to downstream jobs via envInject
62 echo "Recording scenario name for downstream jobs"
63 rm /tmp/$GERRIT_CHANGE_NUMBER/scenario.properties
64 echo "DEPLOY_SCENARIO=$DEPLOY_SCENARIO" > /tmp/$GERRIT_CHANGE_NUMBER/scenario.properties