Skip to content

Commit

Permalink
update: update print style
Browse files Browse the repository at this point in the history
  • Loading branch information
WGrape committed Mar 2, 2024
1 parent 6d549c7 commit dbf2901
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
21 changes: 15 additions & 6 deletions .pipeline/internal/helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,18 @@ print_warn() {
printf "\e[33m$1\e[0m"
}

# print step message.
print_step() {
if [ "$STAGE_ID" = "" ]; then
STAGE_ID=0
fi
((STAGE_ID++))
printf "\033[32m\n+++++ step$STAGE_ID: $1 +++++\033[0m\n\n"
}

# print the environment variables.
print_env(){
echo "================ [variables] ================"
show_env(){
print_step "show_env: ${job_name}"
echo "1. cat /proc/version="$(cat /proc/version)
echo "2. CI_BUILDS_DIR=${CI_BUILDS_DIR}"
echo "3. pwd="$(pwd)
Expand All @@ -24,13 +33,13 @@ print_env(){

# before job
before_job() {
echo "------------ before the job: ${job_name} ------------"
print_env
print_step "before the job: ${job_name}"
show_env
return 0
}

run_job() {
echo "------------ running the job: ${job_name} ------------"
print_step "running the job: ${job_name}"
if ! bash "${global_job_path}"; then
print_error "job fail: ${global_job_name}"
return 1
Expand All @@ -40,7 +49,7 @@ run_job() {

# after job
after_job() {
echo "------------ after the job: ${job_name} ------------"
print_step "after the job: ${job_name}"
return 0
}

Expand Down
12 changes: 6 additions & 6 deletions .pipeline/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,27 @@ for job_name in "${job_queue[@]}"; do
global_trigger_cmd="${global_job_name^^}_TRIGGER_CMD"

# check if the switch is on
switch_is_on=$(eval echo "$"$global_switch_name)
if [ "${switch_is_on}" != "true" ]; then
print_ok "${global_job_name} is skipped due to the switch is off"
switch_status=$(eval echo "$"$global_switch_name)
if [ "${switch_status}" != "on" ]; then
print_ok "${global_job_name} is skipped due to the switch is off\n"
continue
fi

# before job
if ! before_job; then
print_error "pipline exit, before_job failed: ${global_job_name}"
print_error "pipline exit, before_job failed: ${global_job_name}\n"
exit 1
fi

# run job
if ! run_job; then
print_error "pipline exit, run_job failed: ${global_job_path} failed"
print_error "pipline exit, run_job failed: ${global_job_path} failed\n"
exit 1
fi

# after job
if ! after_job; then
print_error "pipline exit, after_job failed: ${global_job_name}"
print_error "pipline exit, after_job failed: ${global_job_name}\n"
exit 1
fi
done

0 comments on commit dbf2901

Please sign in to comment.