Skip to content

Commit

Permalink
Merge pull request #89 from veezor/change-newrelic-command
Browse files Browse the repository at this point in the history
Use jq to create a correct json
  • Loading branch information
MatheusdeMelo authored Aug 29, 2024
2 parents 69a6ac7 + a334c0f commit 0cf7249
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -122,28 +122,37 @@ if [[ $deploy_process_type != "scheduledtasks" && ( -z "$ECS_SERVICE_TASK_PROCES
if [[ ! -z "$NEW_RELIC_API_KEY" && ! -z "$NEW_RELIC_APP_ID" ]]; then
echo "----> Registering deployment with NewRelic APM"

git_change_log=$(echo $(git log -1 --pretty="format:%B" | sed -e 's/\"//g'))
git_revision_user=$(echo $(git log -1 --pretty="format:%an" | sed -e 's/\"//g'))
git_custom_description=$(echo $(git log -1 --pretty="format:${NEW_RELIC_DESCRIPTION}" | sed -e 's/\"//g'))
git_change_log=$(git log -1 --pretty="format:%B"| head -c 500 | jq -Rs '. | gsub("\""; "")')
git_revision_user=$(git log -1 --pretty="format:%an" | jq -Rs '. | gsub("\""; "")')
git_custom_description=$(git log -1 --pretty="format:${NEW_RELIC_DESCRIPTION}" | jq -Rs '. | gsub("\""; "")')

timestamp=$(date -u +"%Y-%m-%dT%H:%M:%SZ")

json_payload=$(jq -n \
--arg rev "${release_arn#*/}" \
--arg log "$git_change_log" \
--arg desc "$git_custom_description" \
--arg user "$git_revision_user" \
--arg time "$timestamp" \
'{
deployment: {
revision: $rev,
changelog: $log,
description: $desc,
user: $user,
timestamp: $time
}
}'
)

deploy_newrelic_response=$(curl \
-s \
-o /dev/null \
-X POST "https://api.newrelic.com/v2/applications/$NEW_RELIC_APP_ID/deployments.json" \
-X POST "https://api.newrelic.com/v2/applications/$NEW_RELIC_APP_ID/deployments.json" \
-H "Api-Key:$NEW_RELIC_API_KEY" \
-w "%{http_code}" \
-H "Content-Type: application/json" \
-d \
"{
\"deployment\": {
\"revision\": \"${release_arn#*/}\",
\"changelog\": \"${git_change_log}\",
\"description\": \"${git_custom_description}\",
\"user\": \"${git_revision_user}\",
\"timestamp\": \"${timestamp}\"
}
}"
-d "$json_payload"
)

if test $deploy_newrelic_response -ne 201; then
Expand Down

0 comments on commit 0cf7249

Please sign in to comment.