Commit 60390b5b authored by Emeric Verschuur's avatar Emeric Verschuur

Add debug-script option

parent 44f8a358
......@@ -134,8 +134,10 @@ citbx_job_finish() {
return 0
fi
for hook in $citbx_job_stage_after; do
$citbx_before_script
cd $CI_PROJECT_DIR
$hook $CITBX_EXIT_CODE
$citbx_after_script
done
if [ "$CITBX_EXIT_CODE" == "0" ]; then
print_info "CI job success!"
......@@ -158,9 +160,18 @@ if [ "$GITLAB_CI" == "true" ]; then
. $CITBX_JOB_RUN_FILE_PATH
citbx_register_handler "job" "main"
citbx_register_handler "job" "after"
if [ "$CITBX_DEBUG_SCRIPT_ENABLED" == "true" ]; then
citbx_before_script="set -x"
citbx_after_script="set +x"
else
citbx_before_script=""
citbx_after_script=""
fi
for hook in $citbx_job_stage_before; do
$citbx_before_script
cd $CI_PROJECT_DIR
$hook
$citbx_after_script
done
CITBX_JOB_START_TIME=$(date +%s)
trap citbx_job_finish EXIT SIGINT SIGTERM
......@@ -169,8 +180,10 @@ if [ "$GITLAB_CI" == "true" ]; then
print_critical "Funtion job_main not found in the file $CITBX_JOB_RUN_FILE_PATH"
fi
for hook in $citbx_job_stage_main; do
$citbx_before_script
cd $CI_PROJECT_DIR
$hook
$citbx_after_script
done
exit 0
fi
......@@ -485,6 +498,9 @@ case "$command" in
CITBX_USER_GROUPS=(adm plugdev)
bashopts_declare -n CITBX_USER_GROUPS -l group -t string -m add \
-d "User group list"
bashopts_declare -n CITBX_DEBUG_SCRIPT_ENABLED -o x -l debug-script -t boolean \
-d "Enable SHELL script debug (set -e)"
citbx_export CITBX_DEBUG_SCRIPT_ENABLED
bashopts_declare -n CITBX_RUN_SHELL -o s -l run-shell -t boolean \
-d "Run a shell instead of run the default command (override CITBX_COMMAND option)"
bashopts_declare -n CITBX_JOB_SHELL -l shell -t string -v "$CITBX_DEFAULT_JOB_SHELL" \
......@@ -503,6 +519,7 @@ case "$command" in
citbx_register_handler "job" "setup"
fi
for hook in $citbx_job_stage_define; do
cd $CI_PROJECT_DIR
$hook
done
;;
......@@ -547,11 +564,6 @@ if [ -n "$CI_REGISTRY" ] \
docker login $CI_REGISTRY
fi
# Run the job setup hooks
for hook in $citbx_job_stage_setup; do
$hook
done
# Compute commands from before_script script and after_script
CITBX_JOB_SCRIPT='
print_info() {
......@@ -563,6 +575,9 @@ print_error() {
print_cmd() {
printf "\e[1m\e[92m$ %s\e[0m\n" "$@"
}
'$(if [ "$CITBX_DEBUG_SCRIPT_ENABLED" == "true" ]; then
echo "set -x"
fi)'
__job_exit_code__=0
(
'
......@@ -643,6 +658,21 @@ CITBX_JOB_DOCKER_RUN_ARGS+=(-e CI_COMMIT_REF_NAME="$CI_COMMIT_REF_NAME")
# Add variable to the environment list
CITBX_ENV_EXPORT_LIST+=(CI_JOB_NAME CI_REGISTRY CI_PROJECT_DIR)
if [ "$CITBX_DEBUG_SCRIPT_ENABLED" == "true" ]; then
citbx_before_script="set -x"
citbx_after_script="set +x"
else
citbx_before_script=""
citbx_after_script=""
fi
# Run the job setup hooks
for hook in $citbx_job_stage_setup; do
$citbx_before_script
$hook
$citbx_after_script
done
case "$CITBX_JOB_EXECUTOR" in
shell)
print_info "Running the job $CI_JOB_NAME into the shell $CITBX_JOB_SHELL..."
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment