I'm building a jenkins job where depending on a choice parameter ($APP) it will use pref variable and "attach" to the host name
The hostname will be used in ansible playbook to deploy the applicaion and use --limit to point the host we define in the choice parameter I defined as HOST1
case $APP in
"app01")
PREF=WS-APP01;;
"app02")
PREF=WS-APP02;;
"app03")
PREF=WS-app03;;
*)
exit 2;;
esac
H2=""
H3=""
if ! [ -z $HOSTS3 ]
then
H3="$PREF_${HOSTS3}*:"
fi
if ! [ -z $HOSTS2 ]
then
H2="$PREF_${HOSTS2}*:"
fi
HOSTS="$PREF_${HOSTS1}*:$H2:$H3"
echo $PREF_$HOSTS1
Up until here seems quite simple and self explanatory.
But when I run to test the echo, it only returns the host foun in $HOSTS1
10:28:58 case $APP in
10:28:58 PREF=APP01
10:28:58 H2=
10:28:58 H3=
10:28:58 '[' -z ']'
10:28:58 '[' -z ']'
10:28:58 HOSTS='qaaciapp00001v*::'
10:28:58 echo qaaciapp00001v
Tried to google this behavior but no success finding an explanation. Thank you in advance.
CodePudding user response:
Try one of the following for the echo.
echo "$PREF_$HOSTS1"
or
echo "\$PREF_$HOSTS1"
CodePudding user response:
Brackets... Brackets saved the day...
case $APP in
"app01")
PREF=WS-APP01;;
"app02")
PREF=WS-APP02;;
"app03")
PREF=WS-app03;;
*)
exit 2;;
esac
H2=""
H3=""
if ! [ -z $HOSTS3 ]
then
H3="${PREF}_${HOSTS3}*:"
fi
if ! [ -z $HOSTS2 ]
then
H2="${PREF}_${HOSTS2}:"
fi
HOSTS="${PREF}_${HOSTS1}:$H2:$H3"
echo ${PREF}_${HOSTS1}
Thank you very much for you assistance ycr