2828 exit 1
2929fi
3030
31+ # Parse arguments for --ci flag (starting from 2nd argument)
32+ ci=false
33+ for (( i= 2 ; i<= $# ; i++ )) ; do
34+ if [[ " ${! i} " == " --ci" ]]; then
35+ ci=true
36+ break
37+ fi
38+ done
3139
3240echo " INFO: Update kubeconfig"
3341aws eks update-kubeconfig --name atlas-" $ENVIRONMENT_NAME " -cluster --region " $REGION "
@@ -45,7 +53,7 @@ echo "INFO: Execution environment pod name: $exec_pod_name"
4553
4654# Ensure tmux is installed in the pod (using apk for Alpine)
4755echo " INFO: Ensuring tmux is available in the pod"
48- kubectl exec -it " $exec_pod_name " -n atlassian -- sh -c " command -v tmux || apk add --no-cache tmux"
56+ kubectl exec -i " $exec_pod_name " -n atlassian -- sh -c " command -v tmux || apk add --no-cache tmux"
4957
5058# Check if tmux session already exists and contains our setup
5159session_exists=$( kubectl exec " $exec_pod_name " -n atlassian -- sh -c " tmux has-session -t bzt_session 2>/dev/null; echo \$ ?" )
97105 "
98106
99107 # Start tmux session with the complete setup and execution
100- kubectl exec -it " $exec_pod_name " -n atlassian -- sh -c "
108+ kubectl exec -i " $exec_pod_name " -n atlassian -- sh -c "
109+ rm -f /tmp/bzt_session.log
101110 tmux new-session -d -s bzt_session \" $setup_script \"
111+ tmux pipe-pane -t bzt_session \" cat > /tmp/bzt_session.log\"
102112 "
103113
104114 echo " INFO: Tmux session 'bzt_session' created with setup and execution"
@@ -119,9 +129,28 @@ while [ $attempt -le $max_attempts ]; do
119129 break
120130 fi
121131
122-
123- kubectl exec -it " $exec_pod_name " -n atlassian -- tmux attach-session -t bzt_session 2> /dev/null
124- exit_code=$?
132+ # Different behavior based on ci flag
133+ if [[ " $ci " == " true" ]]; then
134+ # CI mode: stream logs from /tmp/bzt_session.log (non-interactive)
135+ kubectl exec " $exec_pod_name " -n atlassian -- sh -c "
136+ tail -f /tmp/bzt_session.log &
137+ tail_pid=\$ !
138+
139+ while true; do
140+ sleep 5
141+ if ! tmux has-session -t bzt_session 2>/dev/null; then
142+ break
143+ fi
144+ done
145+
146+ kill \$ tail_pid 2>/dev/null || true
147+ " 2> /dev/null
148+ exit_code=$?
149+ else
150+ # Interactive mode: attach to tmux session
151+ kubectl exec -it " $exec_pod_name " -n atlassian -- tmux attach-session -t bzt_session 2> /dev/null
152+ exit_code=$?
153+ fi
125154
126155 # Handle different exit scenarios
127156 if [[ $exit_code -eq 0 ]]; then
@@ -136,7 +165,7 @@ while [ $attempt -le $max_attempts ]; do
136165 echo " INFO: Session still active, continuing to monitor..."
137166 elif [[ $exit_code -ne 0 ]]; then
138167 # Handle network errors or other failures
139- echo " WARNING: Connection error detected (exit code: $exit_code )"
168+ echo " WARNING: Connection lost (exit code: $exit_code )"
140169
141170 # Verify session still exists before retrying
142171 session_exists=$( kubectl exec " $exec_pod_name " -n atlassian -- sh -c " tmux has-session -t bzt_session 2>/dev/null; echo \$ ?" 2> /dev/null)
0 commit comments