-
Notifications
You must be signed in to change notification settings - Fork 0
Create opslevel-deploy.yml #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,91 @@ | ||||||||
| parameters: | ||||||||
| - name: 'env' | ||||||||
| default: 'Production' | ||||||||
| type: string | ||||||||
| - name: 'integrationId' | ||||||||
| type: string | ||||||||
| - name: 'serviceAlias' | ||||||||
| type: string | ||||||||
| - name: 'apiUrl' | ||||||||
| default: 'https://app.opslevel.com/' | ||||||||
| type: string | ||||||||
|
|
||||||||
| jobs: | ||||||||
| - job: deploy | ||||||||
| steps: | ||||||||
| - script: | | ||||||||
| #!/bin/bash | ||||||||
|
|
||||||||
| # Exit immediately if a command exits with a non-zero status | ||||||||
| set -e | ||||||||
|
|
||||||||
| # Variables (modify or provide dynamically in Azure pipeline environment) | ||||||||
| DEPLOYER_ID="$(Build.QueuedById)" | ||||||||
| DEPLOYER_ID="${DEPLOYER_ID:-$(Build.QueuedById)}" | ||||||||
|
Comment on lines
+23
to
+24
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| DEPLOYER_EMAIL="$(Build.RequestedForEmail)" | ||||||||
| DEPLOYER_NAME="$(Build.RequestedFor)" | ||||||||
| DEPLOY_NUMBER="$(Build.BuildNumber)" | ||||||||
| DEPLOY_URL="$(Build.BuildUri)" | ||||||||
| VERSION="${VERSION:-$(git rev-parse --short HEAD)}" # Default to the current git commit hash | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| DESCRIPTION="${DESCRIPTION:-"Deployed by CI Pipeline: Deploy #${DEPLOY_NUMBER}"}" | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this works in AzureDevOps |
||||||||
| COMMIT_SHA="${COMMIT_SHA:-$(git rev-parse HEAD)}" | ||||||||
| COMMIT_MESSAGE="${COMMIT_MESSAGE:-$(git log -1 --pretty=%B)}" | ||||||||
| COMMIT_BRANCH="${COMMIT_BRANCH:-$(git rev-parse --abbrev-ref HEAD)}" | ||||||||
| COMMIT_DATE="${COMMIT_DATE:-$(git show --no-patch --format='%cd')}" | ||||||||
| COMMITTER_NAME="${COMMITTER_NAME:-$(git show --no-patch --format='%cn')}" | ||||||||
| COMMITTER_EMAIL="${COMMITTER_EMAIL:-$(git show --no-patch --format='%ce')}" | ||||||||
| AUTHOR_NAME="${AUTHOR_NAME:-$(git show --no-patch --format='%an')}" | ||||||||
| AUTHOR_EMAIL="${AUTHOR_EMAIL:-$(git show --no-patch --format='%ae')}" | ||||||||
| AUTHORING_DATE="${AUTHORING_DATE:-$(git show --no-patch --format='%ad')}" | ||||||||
|
Comment on lines
+31
to
+39
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All of these have input environment variables - my understanding is they will always be blank. So 2 things
|
||||||||
| DEPLOYED_AT="`date -u +%Y-%m-%dT%H:%M:%SZ`" | ||||||||
|
|
||||||||
|
|
||||||||
| # API endpoint, Routing ID and Service Alias | ||||||||
| OPSLEVEL_ENDPOINT="${{ parameters.apiUrl }}integrations/deploy/" | ||||||||
| DEPLOYMENT_ENV="${{ parameters.env }}" | ||||||||
| OPSLEVEL_ROUTING_ID="${{ parameters.integrationId }}" | ||||||||
| SERVICE_ALIAS="${{ parameters.serviceAlias }}" | ||||||||
|
|
||||||||
| # Payload for the OpsLevel API | ||||||||
| data="{ | ||||||||
| \"dedup_id\": \"$(uuidgen)\", | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This shouldn't be a unique ID per invocation - it should be the |
||||||||
| \"service\": \"$SERVICE_ALIAS\", | ||||||||
| \"deployer\": { | ||||||||
| \"id\": \"$DEPLOYER_ID\", | ||||||||
| \"email\": \"$DEPLOYER_EMAIL\", | ||||||||
| \"name\": \"$DEPLOYER_NAME\" | ||||||||
| }, | ||||||||
| \"deployed_at\": \"$DEPLOYED_AT\", | ||||||||
| \"environment\": \"$DEPLOYMENT_ENV\", | ||||||||
| \"description\": \"$DESCRIPTION\", | ||||||||
| \"deploy_url\": \"$DEPLOY_URL\", | ||||||||
| \"deploy_number\": \"$DEPLOY_NUMBER\", | ||||||||
| \"commit\": { | ||||||||
| \"sha\": \"$COMMIT_SHA\", | ||||||||
| \"message\": \"$COMMIT_MESSAGE\", | ||||||||
| \"branch\": \"$COMMIT_BRANCH\", | ||||||||
| \"date\": \"$COMMIT_DATE\", | ||||||||
| \"committer_name\": \"$COMMITTER_NAME\", | ||||||||
| \"committer_email\": \"$COMMITTER_EMAIL\", | ||||||||
| \"author_name\": \"$AUTHOR_NAME\", | ||||||||
| \"author_email\": \"$AUTHOR_EMAIL\", | ||||||||
| \"authoring_date\": \"$AUTHORING_DATE\" | ||||||||
| } | ||||||||
| }" | ||||||||
|
|
||||||||
| echo "$data" | ||||||||
|
|
||||||||
| # Send data to OpsLevel | ||||||||
| response=$(curl -s -i -X POST "$OPSLEVEL_ENDPOINT" \ | ||||||||
| -H "Content-Type: application/json" \ | ||||||||
| -H "X-OpsLevel-Routing-ID: $OPSLEVEL_ROUTING_ID" \ | ||||||||
| -d "$data") | ||||||||
|
|
||||||||
| # Check response for errors | ||||||||
| echo "$response" | grep -q '"errors"' && { | ||||||||
| echo "Error sending deployment data to OpsLevel: $response" | ||||||||
| exit 1 | ||||||||
| } | ||||||||
|
|
||||||||
| echo "Deployment data successfully sent to OpsLevel." | ||||||||
| displayName: 'Send OpsLevel Deployment Details' | ||||||||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alphabetize by parameters name