@@ -30,55 +30,57 @@ steps:
3030 force="<< parameters.force >>"
3131 if [[ $force == true ]]; then
3232 vfcli env delete --name "<< parameters.env-name >>" --interactive false
33- else
34- if [[ -f << parameters.env-name-path >> ]]; then
35- env_name=$(cat << parameters.env-name-path >>)
36- echo "Env: $env_name will be released"
37- else
38- env_name="null"
39- echo "Env name file was not found. Will proceed to deleting the environment."
40- fi
41- if [[ "$env_name" != "null" ]] && [[ -n "$env_name" ]]; then
42- echo "Releasing the environment..... $env_name"
43- vfcli pool release-env --env-name "$env_name"
44- if [[ << parameters.reset-db >> == true ]]; then
45- echo "Resetting the database for $env_name"
46- echo "Triggering pipeline with env-name parameter"
47- response=$(curl -s -w "\n%{http_code}" \
48- --request POST \
49- --url "https://circleci.com/api/v2/project/gh/voiceflow/env-release-system/pipeline" \
50- --header "Circle-Token: ${CIRCLECI_API_TOKEN}" \
51- --header "content-type: application/json" \
52- --data "{\"parameters\":{\"e2e_env_name\":\"$env_name\",\"trigger_pipeline\":true}}")
53- http_status=$(echo "$response" | tail -n1)
54- response_body=$(echo "$response" | sed '$d')
55- if [[ $http_status == "201" || $http_status == "200" ]]; then
56- if echo "$response_body" | jq empty 2>/dev/null; then
57- pipeline_id=$(echo "$response_body" | jq -r '.id // empty')
58- pipeline_number=$(echo "$response_body" | jq -r '.number // empty')
59- if [[ -n $pipeline_number ]]; then
60- pipeline_url="https://app.circleci.com/pipelines/github/voiceflow/env-release-system/$pipeline_number"
61- echo "Env Release Pipeline triggered successfully."
62- echo "Pipeline URL: $pipeline_url"
63- echo "Pipeline ID: $pipeline_id"
64- echo "Exiting with success."
65- exit 0
66- else
67- echo "Failed to retrieve pipeline number. Response body: $response_body"
68- fi
69- else
70- echo "Response is not valid JSON. Response body: $response_body"
71- fi
33+ exit 0
34+ fi
35+
36+ if [ ! -f << parameters.env-name-path >> ] ||
37+ [ "$(cat << parameters.env-name-path >> )" == "null" ] ||
38+ [ -z "$(cat << parameters.env-name-path >> )" ]; then
39+
40+ echo "Env name file was not found. Will proceed to deleting the environment."
41+ echo "Kick-starting the deletion of the environment."
42+ vfcli env delete --name "<< parameters.env-name >>" --interactive false
43+ exit 0
44+ fi
45+
46+ env_name=$(cat << parameters.env-name-path >>)
47+ echo "Env: $env_name will be released"
48+
49+ echo "Releasing the environment..... $env_name"
50+ vfcli pool release-env --env-name "$env_name"
51+ if [[ << parameters.reset-db >> == true ]]; then
52+ echo "Resetting the database for $env_name"
53+ echo "Triggering pipeline with env-name parameter"
54+ response=$(curl -s -w "\n%{http_code}" \
55+ --request POST \
56+ --url "https://circleci.com/api/v2/project/gh/voiceflow/env-release-system/pipeline" \
57+ --header "Circle-Token: ${CIRCLECI_API_TOKEN}" \
58+ --header "content-type: application/json" \
59+ --data "{\"parameters\":{\"e2e_env_name\":\"$env_name\",\"trigger_pipeline\":true}}")
60+ http_status=$(echo "$response" | tail -n1)
61+ response_body=$(echo "$response" | sed '$d')
62+ if [[ $http_status == "201" || $http_status == "200" ]]; then
63+ if echo "$response_body" | jq empty 2>/dev/null; then
64+ pipeline_id=$(echo "$response_body" | jq -r '.id // empty')
65+ pipeline_number=$(echo "$response_body" | jq -r '.number // empty')
66+ if [[ -n $pipeline_number ]]; then
67+ pipeline_url="https://app.circleci.com/pipelines/github/voiceflow/env-release-system/$pipeline_number"
68+ echo "Env Release Pipeline triggered successfully."
69+ echo "Pipeline URL: $pipeline_url"
70+ echo "Pipeline ID: $pipeline_id"
71+ echo "Exiting with success."
72+ exit 0
7273 else
73- echo "Failed to trigger pipeline. HTTP status code: $http_status"
74- echo "Response body: $response_body"
74+ echo "Failed to retrieve pipeline number. Response body: $response_body"
7575 fi
76+ else
77+ echo "Response is not valid JSON. Response body: $response_body"
7678 fi
77- vfcli env resume "$env_name" --interactive false
78- vfcli track attach --branch master --components all --name "$env_name" --interactive false --no-circleci
79- vfcli pool free-env --env-name "$env_name"
8079 else
81- echo "Kick-starting the deletion of the environment. "
82- vfcli env delete --name "<< parameters.env-name >>" --interactive false
80+ echo "Failed to trigger pipeline. HTTP status code: $http_status "
81+ echo "Response body: $response_body"
8382 fi
8483 fi
84+ vfcli env resume "$env_name" --interactive false
85+ vfcli track attach --branch master --components all --name "$env_name" --interactive false --no-circleci
86+ vfcli pool free-env --env-name "$env_name"
0 commit comments