Created
July 30, 2025 14:52
-
-
Save cremerfc/dcdd6daaebe01bfd8a4ecab2e924374c to your computer and use it in GitHub Desktop.
Azure DevOps Pipeline
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trigger: | |
branches: | |
include: | |
- main | |
- develop | |
pr: | |
branches: | |
include: | |
- main | |
variables: | |
CORTEX_API_URL: 'https://api.getcortexapp.com/api/v1/catalog' | |
pool: | |
vmImage: 'ubuntu-latest' | |
stages: | |
- stage: Build | |
displayName: 'Build Stage' | |
jobs: | |
- job: BuildJob | |
displayName: 'Build Application' | |
steps: | |
- task: NodeTool@0 | |
inputs: | |
versionSpec: '18.x' | |
displayName: 'Install Node.js' | |
- script: | | |
echo "Building application..." | |
npm ci | |
npm run build | |
displayName: 'Build Application' | |
- publish: dist | |
artifact: BuildArtifacts | |
displayName: 'Publish Build Artifacts' | |
- stage: Test | |
displayName: 'Test Stage' | |
dependsOn: Build | |
jobs: | |
- job: TestJob | |
displayName: 'Run Tests' | |
steps: | |
- task: NodeTool@0 | |
inputs: | |
versionSpec: '18.x' | |
displayName: 'Install Node.js' | |
- script: | | |
echo "Running tests..." | |
npm ci | |
npm test | |
displayName: 'Run Tests' | |
- stage: Deploy | |
displayName: 'Deploy Stage' | |
dependsOn: Test | |
jobs: | |
- job: DeployJob | |
displayName: 'Deploy to Staging' | |
steps: | |
- script: | | |
echo "Deploying to staging..." | |
sleep 2 | |
echo "Deployment completed" | |
displayName: 'Deploy Application' | |
- stage: Notify | |
displayName: 'Notify Cortex' | |
dependsOn: | |
- Build | |
- Test | |
- Deploy | |
condition: always() | |
jobs: | |
- job: NotifyJob | |
displayName: 'Send Cortex Notification' | |
steps: | |
- checkout: none | |
- bash: | | |
echo "Build Stage Result: $(stageDependencies.Build.BuildJob.result)" | |
echo "Test Stage Result: $(stageDependencies.Test.TestJob.result)" | |
echo "Deploy Stage Result: $(stageDependencies.Deploy.DeployJob.result)" | |
# Determine overall pipeline status | |
BUILD_RESULT="$(stageDependencies.Build.BuildJob.result)" | |
TEST_RESULT="$(stageDependencies.Test.TestJob.result)" | |
DEPLOY_RESULT="$(stageDependencies.Deploy.DeployJob.result)" | |
if [ "$BUILD_RESULT" = "Succeeded" ] && [ "$TEST_RESULT" = "Succeeded" ] && [ "$DEPLOY_RESULT" = "Succeeded" ]; then | |
PIPELINE_STATUS="success" | |
DEPLOY_TYPE="DEPLOY" | |
MESSAGE="Pipeline completed successfully" | |
else | |
PIPELINE_STATUS="failed" | |
DEPLOY_TYPE="ROLLBACK" | |
MESSAGE="Pipeline failed - one or more stages failed (Build: $BUILD_RESULT, Test: $TEST_RESULT, Deploy: $DEPLOY_RESULT)" | |
fi | |
echo "Pipeline Status: $PIPELINE_STATUS" | |
echo "Deploy Type: $DEPLOY_TYPE" | |
echo "Message: $MESSAGE" | |
# Convert repo name to lowercase (extract from full repository name) | |
REPO_NAME=$(echo "$(Build.Repository.Name)" | cut -d'/' -f2 | tr '[:upper:]' '[:lower:]') | |
echo "Repository: $REPO_NAME" | |
# Get current timestamp | |
TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%SZ") | |
# Get deployer information | |
DEPLOYER_EMAIL="${BUILD_REQUESTEDFOREMAIL:[email protected]}" | |
DEPLOYER_NAME="${BUILD_REQUESTEDFOR:-Azure DevOps}" | |
# Send notification to Cortex | |
curl -L \ | |
--request POST \ | |
--max-time 30 \ | |
--retry 2 \ | |
--url "$(CORTEX_API_URL)/$REPO_NAME/deploys" \ | |
--header "Authorization: Bearer $(CORTEX_TOKEN)" \ | |
--header "Content-Type: application/json" \ | |
--data "{ | |
\"customData\": { | |
\"pipeline_id\": \"$(Build.BuildId)\", | |
\"build_number\": \"$(Build.BuildNumber)\", | |
\"branch\": \"$(Build.SourceBranchName)\", | |
\"pipeline_status\": \"$PIPELINE_STATUS\", | |
\"message\": \"$MESSAGE\", | |
\"build_url\": \"$(System.TeamFoundationCollectionUri)$(System.TeamProject)/_build/results?buildId=$(Build.BuildId)\", | |
\"project\": \"$(System.TeamProject)\", | |
\"repository\": \"$(Build.Repository.Name)\" | |
}, | |
\"deployer\": { | |
\"email\": \"$DEPLOYER_EMAIL\", | |
\"name\": \"$DEPLOYER_NAME\" | |
}, | |
\"environment\": \"staging\", | |
\"sha\": \"$(Build.SourceVersion)\", | |
\"timestamp\": \"$TIMESTAMP\", | |
\"title\": \"Pipeline $PIPELINE_STATUS - $(Build.Repository.Name)\", | |
\"type\": \"$DEPLOY_TYPE\", | |
\"url\": \"$(System.TeamFoundationCollectionUri)$(System.TeamProject)/_build/results?buildId=$(Build.BuildId)\" | |
}" | |
if [ $? -eq 0 ]; then | |
echo "Successfully notified Cortex" | |
else | |
echo "Failed to notify Cortex, but continuing..." | |
fi | |
displayName: 'Send Cortex Notification' | |
env: | |
CORTEX_TOKEN: $(CORTEX_TOKEN) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment