diff --git a/.lagoon.yml b/.lagoon.yml index 8895d1dbf..59d5c8d40 100644 --- a/.lagoon.yml +++ b/.lagoon.yml @@ -14,7 +14,7 @@ tasks: command: | GH_DEPLOYMENT=$(curl -L -X POST -H "Authorization: Bearer $GH_DEPLOYMENT_TOKEN" \ https://api.github.com/repos/danskernesdigitalebibliotek/dpl-cms/deployments \ - -d "{\"ref\":\"$LAGOON_PR_HEAD_BRANCH\", \"environment\":\"$LAGOON_PR_HEAD_BRANCH\", \ + -d "{\"ref\":\"$LAGOON_PR_HEAD_BRANCH\", \"environment\":\"$LAGOON_ENVIRONMENT\", \ \"description\":\"Triggered by Lagoon\", \"transient_environment\": true, \ \"auto_merge\": false, \"required_contexts\": []}") @@ -22,7 +22,13 @@ tasks: GH_DEPLOYMENT_ID=$(echo "$GH_DEPLOYMENT" | grep -m 1 '"id":' | sed -E 's/.*"id": ([0-9]+),.*/\1/') echo "Created GH deployment with ID '$GH_DEPLOYMENT_ID'" - echo "$GH_DEPLOYMENT_ID" > /tmp/gh_deployment_id + + # The only way to keep a value between tasks, is saving it in a + # file. Environment variables are killed between tasks, apart from + # the global ones. + echo "$GH_DEPLOYMENT_ID" > /tmp/GH_DEPLOYMENT_ID + LAGOON_DEPLOYS_LOG_URL=$(echo "https://ui.lagoon.dplplat01.dpl.reload.dk/projects/$LAGOON_PROJECT/dpl-cms-$LAGOON_ENVIRONMENT/deployments") + echo "$LAGOON_DEPLOYS_URL" > /tmp/LAGOON_DEPLOYS_LOG_URL service: cli - run: name: If drupal is not installed @@ -122,7 +128,9 @@ tasks: DRUPAL_URL=$(drush browse) # Read the deployment ID from the file - GH_DEPLOYMENT_ID=$(cat /tmp/gh_deployment_id) + GH_DEPLOYMENT_ID=$(cat /tmp/GH_DEPLOYMENT_ID) + LAGOON_DEPLOYS_LOG_URL=$(cat /tmp/LAGOON_DEPLOYS_LOG_URL) + echo "Setting GH deployment status '$GH_DEPLOYMENT_ID': '$DEPLOYMENT_STATUS'" # Setting the deployment status, on the GH deployment created earlier. @@ -130,7 +138,8 @@ tasks: -X POST \ -H "Authorization: Bearer $GH_DEPLOYMENT_TOKEN" \ https://api.github.com/repos/danskernesdigitalebibliotek/dpl-cms/deployments/$GH_DEPLOYMENT_ID/statuses \ - -d "{\"environment\":\"$LAGOON_PR_HEAD_BRANCH\",\"state\":\"$DEPLOYMENT_STATUS\", \"target_url\":\"$DRUPAL_URL\"}" + -d "{\"environment\":\"$LAGOON_ENVIRONMENT\",\"state\":\"$DEPLOYMENT_STATUS\", \ + \"environment_url\":\"$DRUPAL_URL\", \"log_url\":\"$LAGOON_DEPLOYS_LOG_URL\"}" service: cli environments: diff --git a/dev-scripts/lagoon-error-handling.sh b/dev-scripts/lagoon-error-handling.sh index d80026f05..1e2362c68 100755 --- a/dev-scripts/lagoon-error-handling.sh +++ b/dev-scripts/lagoon-error-handling.sh @@ -6,13 +6,14 @@ error_handler() { DEPLOYMENT_STATUS="failure" GH_DEPLOYMENT_ID=$(cat /tmp/gh_deployment_id) + LAGOON_DEPLOYS_LOG_URL=$(cat /tmp/LAGOON_DEPLOYS_LOG_URL) echo "Setting GH deployment status '$GH_DEPLOYMENT_ID': '$DEPLOYMENT_STATUS'" curl -L \ -X POST \ -H "Authorization: Bearer $GH_DEPLOYMENT_TOKEN" \ https://api.github.com/repos/danskernesdigitalebibliotek/dpl-cms/deployments/"$GH_DEPLOYMENT_ID"/statuses \ - -d "{\"environment\":\"$LAGOON_PR_HEAD_BRANCH\",\"state\":\"$DEPLOYMENT_STATUS\"}" + -d "{\"environment\":\"$LAGOON_ENVIRONMENT\",\"log_url\":\"$LAGOON_DEPLOYS_LOG_URL\",\"state\":\"$DEPLOYMENT_STATUS\"}" # As we've gotten rid of set -e in lagoon.yml, it is very important to exit # here, otherwise, lagoon will think a faulty deploy has succeeded.