diff --git a/scripts/trigger.sh b/scripts/trigger.sh index 3911358..fdbfd20 100755 --- a/scripts/trigger.sh +++ b/scripts/trigger.sh @@ -8,6 +8,27 @@ # the environment or from the SOLUTION file) # +YES= + +PROJECT=$(basename $(pwd)) + +while getopts ydp: opt; do + case "${opt}" in + p) + PROJECT=${OPTARG} + ;; + y) + YES=1 + ;; + [?]) + >&2 echo -e "\nInvalid parameter: ${opt}\n" + usage >&2 + exit 1 + ;; + esac +done +shift $(( OPTIND-1 )) + TRIGGER_VARS=( OS_DISTRO OS_RELEASE @@ -28,9 +49,10 @@ done # Bring in the variables from SOLUTION file, supporting # nested substitution -. SOLUTION +[[ -e SOLUTION ]] && . SOLUTION -VARS=($(sed -nE "s,(^[^#][^=]*).*$,\1,pg" SOLUTION)) +VARS=() +[[ -e SOLUTION ]] && VARS=($(sed -nE "s,(^[^#][^=]*).*$,\1,pg" SOLUTION)) for var in ${VARS[@]}; do export ${var} done @@ -41,7 +63,7 @@ BUILD=${BUILD:-7517585} BRANCH=${BRANCH:-releases_19.4} REF=${REF:-master} -PROJECT="vtt/sws/osgc/solutions/$(basename $(pwd))" +PROJECT="vtt/sws/osgc/solutions/${PROJECT}" URI_PROJECT=$(echo ${PROJECT} | sed -E 's,/,%2F,g') eval $(grep ^SYS_OSGC_TOKEN SECRETS) @@ -53,7 +75,7 @@ eval $(grep ^SYS_OSGC_TOKEN SECRETS) GITLAB="https://gitlab.devtools.intel.com" -echo "Looking for CI trigger" +echo "Looking for CI trigger on ${PROJECT}" RESULTS=$(curl --noproxy '*' -s -X GET \ --header "PRIVATE-TOKEN: ${SYS_OSGC_TOKEN}" \ @@ -94,7 +116,7 @@ TOKEN=$(echo ${RESULTS} | sed -E 's#([[{},])#\1\n#g' | { [[ "${TOKEN}" == "" ]] && { echo "'sys_osgc CI trigger' does not exist on ${PROJECT}." - while read -n1 -r -p "Create new trigger [y|N]?"; do + (( YES )) || while read -n1 -r -p "Create new trigger [y|N]? "; do case $REPLY in y|Y) echo "" @@ -110,7 +132,6 @@ TOKEN=$(echo ${RESULTS} | sed -E 's#([[{},])#\1\n#g' | { esac done - RESULTS=$(curl --noproxy '*' -s -X POST \ --header "PRIVATE-TOKEN: ${SYS_OSGC_TOKEN}" \ -F 'description="sys_osgc CI trigger"' \ @@ -179,11 +200,10 @@ done EOF -while read -n1 -r -p "Is this correct [y|N]? "; do +(( YES )) || while read -n1 -r -p "Is this correct [y|N]? "; do case $REPLY in y|Y) echo "" - post break ;; n|N|"") @@ -195,3 +215,5 @@ while read -n1 -r -p "Is this correct [y|N]? "; do ;; esac done + +post