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