I have app_name as a multi-line string parameter, I want to loop it through so I can create ingress objects for applications.
Now, my shell script snippet for the Jenkins file is like below:
echo "${app_name}"
for i in "${app_name}"; do
kubectl delete ing ${i} -n${deployment_namespace}
cp -apvf /tmp/flexicache-ing.yaml /tmp/flexicache-ing-${i}.yaml
pwd
sed -i 's/#{deployment_ns}#/'"${deployment_namespace}"'/' /tmp/flexicache-ing-${i}.yaml
sed -i 's/#{app_name}#/'"${app_name}"'/' /tmp/flexicache-ing-${i}.yaml
sed -i 's/#{chart_name}#/'"${app_name}"'/' /tmp/flexicache-ing-${i}.yaml
kubectl apply -f /tmp/flexicache-ing-${i}.yaml
done
Output:
+ echo 'flexicache-data-processor
flexicache-incident-data-processor'
flexicache-data-processor
flexicache-incident-data-processor
++ tput bold
+ bold=''
++ tput sgr0
+ normal=''
+ for i in '"${app_name}"'
+ kubectl delete ing flexicache-data-processor flexicache-incident-data-processor -nsit1-blue
Error from server (NotFound): ingresses.extensions "flexicache-data-processor" not found
Error from server (NotFound): ingresses.extensions "flexicache-incident-data-processor" not found
+ cp -apvf /tmp/flexicache-ing.yaml /tmp/flexicache-ing-flexicache-data-processor flexicache-incident-data-processor.yaml
cp: target 'flexicache-incident-data-processor.yaml' is not a directory
I have tried it with an array as well but that seems to be not working as well.
Need to understand what I am doing wrong.
P.S: Changed the code to the below:
for i in ${app_name}; do
kubectl delete ing ${i} -n${deployment_namespace}
cp -apvf /tmp/flexicache-ing.yaml /tmp/flexicache-ing-${i}.yaml
pwd
sed -i 's/#{deployment_ns}#/'"${deployment_namespace}"'/' /tmp/flexicache-ing-${i}.yaml
sed -i 's/#{app_name}#/'"${app_name}"'/' /tmp/flexicache-ing-${i}.yaml
sed -i 's/#{chart_name}#/'"${app_name}"'/' /tmp/flexicache-ing-${i}.yaml
kubectl apply -f /tmp/flexicache-ing-${i}.yaml
done
Output is still busted:
+ sed -i 's/#{app_name}#/flexicache-data-processor
flexicache-incident-data-processor/' /tmp/flexicache-ing-flexicache-data-processor.yaml
sed: -e expression #1, char 40: unterminated `s' command
EDIT 2: I did used code of <<< before bt still not woring. Code below:
while IFS= read -r i; do
kubectl delete ing ${i} -n${deployment_namespace}
cp -apvf /tmp/flexicache-ing.yaml /tmp/flexicache-ing-${i}.yaml
pwd
sed -i 's/#{deployment_ns}#/'"${deployment_namespace}"'/' /tmp/flexicache-ing-${i}.yaml
sed -i 's/#{app_name}#/'"${app_name}"'/' /tmp/flexicache-ing-${i}.yaml
sed -i 's/#{chart_name}#/'"${app_name}"'/' /tmp/flexicache-ing-${i}.yaml
kubectl apply -f /tmp/flexicache-ing-${i}.yaml
done <<< "${app_name}"
Output with failed sed...
+ sed -i 's/#{chart_name}#/flexicache-data-processor
flexicache-incident-data-processor/' /tmp/flexicache-ing-flexicache-data-processor.yaml
sed: -e expression #1, char 42: unterminated `s' command
Please do not make the question "duplicate" if you have not fully understood the problem statement.