Updated trigger.sh to output env and solution variables prior to firing trigger
Signed-off-by: James Ketrenos <james.p.ketrenos@intel.com>
This commit is contained in:
parent
7d3c964541
commit
07ac31c5dd
@ -3,14 +3,34 @@
|
|||||||
# 1. List project triggers, looking for 'sys_osgc CI trigger'
|
# 1. List project triggers, looking for 'sys_osgc CI trigger'
|
||||||
# 2. If not found, create the 'sys_osgc CI trigger'
|
# 2. If not found, create the 'sys_osgc CI trigger'
|
||||||
# 3. Invoke the trigger
|
# 3. Invoke the trigger
|
||||||
|
#
|
||||||
|
# The trigger will pass in the following variables (declared from
|
||||||
|
# the environment or from the SOLUTION file)
|
||||||
|
#
|
||||||
|
|
||||||
|
TRIGGER_VARS=(
|
||||||
|
OS_DISTRO
|
||||||
|
OS_RELEASE
|
||||||
|
PACKAGE_STREAM
|
||||||
|
PACKAGE_REPOSITORY
|
||||||
|
BRANCH
|
||||||
|
BUILD
|
||||||
|
REF
|
||||||
|
)
|
||||||
|
|
||||||
|
# Create a copy of the current values for each trigger
|
||||||
|
# variable so we can show which ones were modified by the
|
||||||
|
# SOLUTION import.
|
||||||
|
for variable in ${TRIGGER_VARS[@]}; do
|
||||||
|
def=def_${variable}
|
||||||
|
export ${def}="${!variable}"
|
||||||
|
done
|
||||||
|
|
||||||
# Bring in the variables from SOLUTION file, supporting
|
# Bring in the variables from SOLUTION file, supporting
|
||||||
# nested substitution
|
# nested substitution
|
||||||
. SOLUTION
|
. SOLUTION
|
||||||
. MANIFEST
|
|
||||||
|
|
||||||
VARS=($(sed -nE "s,(^[^#][^=]*).*$,\1,pg" SOLUTION))
|
VARS=($(sed -nE "s,(^[^#][^=]*).*$,\1,pg" SOLUTION))
|
||||||
VARS+=($(sed -nE "s,(^[^#][^=]*).*$,\1,pg" MANIFEST))
|
|
||||||
for var in ${VARS[@]}; do
|
for var in ${VARS[@]}; do
|
||||||
export ${var}
|
export ${var}
|
||||||
done
|
done
|
||||||
@ -110,22 +130,19 @@ TOKEN=$(echo ${RESULTS} | sed -E 's#([[{},])#\1\n#g' | {
|
|||||||
echo "Using token: ${TOKEN}"
|
echo "Using token: ${TOKEN}"
|
||||||
|
|
||||||
function post {
|
function post {
|
||||||
RESULTS=$(curl --noproxy '*' -s -X POST \
|
CMD="curl --noproxy '*' -s -X POST -F token=${TOKEN} -F ref=${REF} "
|
||||||
-F "token=${TOKEN}" \
|
for variable in ${TRIGGER_VARS[@]}; do
|
||||||
-F "ref=${REF}" \
|
CMD+="-F variables[${variable}]=${!variable} "
|
||||||
-F "variables[OS_DISTRO]=${OS_DISTRO}" \
|
done
|
||||||
-F "variables[OS_RELEASE]=${OS_RELEASE}" \
|
CMD+="${GITLAB}/api/v4/projects/${URI_PROJECT}/trigger/pipeline"
|
||||||
-F "variables[PACKAGE_STREAM]=${PACKAGE_STREAM}" \
|
|
||||||
-F "variables[PACKAGE_REPOSITORY]=${PACKAGE_REPOSITORY}" \
|
RESULTS=$(${CMD})
|
||||||
-F "variables[BRANCH]=${BRANCH}" \
|
|
||||||
-F "variables[BUILD]=${BUILD}" \
|
|
||||||
-F "variables[BUILDNUMBER]=${BUILD}" \
|
|
||||||
${GITLAB}/api/v4/projects/${URI_PROJECT}/trigger/pipeline)
|
|
||||||
|
|
||||||
PIPELINE=$(echo ${RESULTS} | sed -nE 's,^.*details_path":"([^"]*)".*,\1,p')
|
PIPELINE=$(echo ${RESULTS} | sed -nE 's,^.*details_path":"([^"]*)".*,\1,p')
|
||||||
|
|
||||||
[[ "${PIPELINE}" == "" ]] && {
|
[[ "${PIPELINE}" == "" ]] && {
|
||||||
>&2 echo "Unable to find pipeline details URL"
|
>&2 echo "Unable to find pipeline details URL when running:"
|
||||||
|
>&2 echo "${CMD}"
|
||||||
>&2 echo ${RESULTS}
|
>&2 echo ${RESULTS}
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
@ -134,8 +151,35 @@ function post {
|
|||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
echo "Triggering pipeline on project ${PROJECT} for BUILD=${BUILD} and BRANCH=${BRANCH}"
|
cat << EOF
|
||||||
while read -n1 -r -p "Is this correct [y|N]?"; do
|
Triggering pipeline on project:
|
||||||
|
|
||||||
|
${PROJECT}
|
||||||
|
|
||||||
|
With the following variables:
|
||||||
|
|
||||||
|
$(
|
||||||
|
has_override=0
|
||||||
|
for variable in ${TRIGGER_VARS[@]}; do
|
||||||
|
def=def_${variable}
|
||||||
|
modified=' '
|
||||||
|
if [[ "${!def}" != "" ]]; then
|
||||||
|
if [[ "${!def}" != "${!variable}" ]]; then
|
||||||
|
modified='*'
|
||||||
|
has_override=1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
echo " ${modified} ${variable}=${!variable}"
|
||||||
|
done
|
||||||
|
|
||||||
|
(( has_override )) && {
|
||||||
|
echo -e " ^\n │\n └── Value set in ENV but modified by SOLUTION file."
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
EOF
|
||||||
|
|
||||||
|
while read -n1 -r -p "Is this correct [y|N]? "; do
|
||||||
case $REPLY in
|
case $REPLY in
|
||||||
y|Y)
|
y|Y)
|
||||||
echo ""
|
echo ""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user